Skip to the content.

用 NVIDIA OpenShell 把 AI Agent 關進沙箱 —— 實作教學

一個小而可重現的 demo:把現成的 coding agent 丟進 NVIDIA OpenShell 核心級沙箱, 套上一份宣告式 YAML policy,再實際證明沙箱會擋掉 policy 禁止的行為——用 audit log 當證據。

撰寫於研讀 NVIDIA DLI 課程《Securing Agents with NemoClaw and OpenShell》 (課號 S-FX-43)期間。

English version: README.md


為什麼這件事重要(30 秒版)

現代 agent 的本質是:模型 + 工具 + 一個持續跑到任務完成的迴圈。 一旦把 shell 權限和對外網路交給這個迴圈,一次壞掉的 tool call 就可能刪檔或外洩資料。

OpenShell 讓 agent 原封不動地跑在沙箱裡,由一份 YAML policy 治理:

而且每一筆 allow / deny 決策都留下 audit log。這個 repo 用大約 15 分鐘把這件事演給你看。

三個角色先搞懂(釐清課程架構)

名稱 角色 一句話
OpenShell 底層安全沙箱 runtime agent 跑在裡面,policy 說了算
NemoClaw 參考堆疊 / 一鍵安裝器 把 OpenShell + 本地模型 + Privacy Router 打包
Hermes / OpenClaw 實際跑的 agent 被沙箱保護的對象

事前準備

重現步驟

完整可複製的指令清單見 STEPS.md。核心流程:

  1. 裝 CLI:curl -LsSf https://raw.githubusercontent.com/NVIDIA/OpenShell/main/install.sh | sh
  2. 把 agent 丟進沙箱:openshell sandbox create -- claude
  3. 套 policy:openshell policy set <name> --policy policies/readonly-github.yaml --wait
  4. 故意違規:叫 agent 對 GitHub API 發 POST(建 issue/gist)或寫檔到 /sandbox 外 → 應被擋下
  5. 匯出 audit log 的 allow/deny 紀錄當證據
  6. 把三張截圖寫成教學

這個 policy 在做什麼

policies/readonly-github.yaml 示範最小可用的治理:

重點:policy 是宣告式 YAML,可以進版控、在 PR 裡被 review——這就是 governance-as-code(治理即程式碼),也是 PM/SA 視角最值得講的一句話。

進度

來源 / 參考