Sandbox CLI
Sandbox CLI
Section titled “Sandbox CLI”管理用於隔離代理程式執行的沙盒執行環境。
OpenClaw 可以在隔離的沙盒執行環境中執行代理程式以確保安全性。sandbox 指令可協助您在更新或變更設定後檢視並重新建立這些執行環境。
目前通常是指:
- Docker 沙盒容器
- 當
agents.defaults.sandbox.backend = "ssh"時的 SSH 沙盒執行環境 - 當
agents.defaults.sandbox.backend = "openshell"時的 OpenShell 沙盒執行環境
對於 ssh 和 OpenShell remote,重新建立的重要性比 Docker 高:
- 初始種子之後,遠端工作區是標準來源
openclaw sandbox recreate會刪除所選範圍的該標準遠端工作區- 下次使用時會從目前的本機工作區再次進行種子設定
openclaw sandbox explain
Section titled “openclaw sandbox explain”檢視有效的沙盒模式/範圍/工作區存取權、沙盒工具原則,以及提升的閘道(包含修復設定金鑰路徑)。
openclaw sandbox explainopenclaw sandbox explain --session agent:main:mainopenclaw sandbox explain --agent workopenclaw sandbox explain --jsonopenclaw sandbox list
Section titled “openclaw sandbox list”列出所有沙盒執行環境及其狀態和設定。
openclaw sandbox listopenclaw sandbox list --browser # List only browser containersopenclaw sandbox list --json # JSON output輸出包含:
- 執行環境名稱和狀態
- 後端 (
docker、openshell等) - 設定標籤以及是否符合目前設定
- 存在時間(建立後經過的時間)
- 閒置時間(上次使用後經過的時間)
- 關聯的工作階段/代理程式
openclaw sandbox recreate
Section titled “openclaw sandbox recreate”移除沙盒執行環境以強制使用更新後的設定進行重新建立。
openclaw sandbox recreate --all # Recreate all containersopenclaw sandbox recreate --session main # Specific sessionopenclaw sandbox recreate --agent mybot # Specific agentopenclaw sandbox recreate --browser # Only browser containersopenclaw sandbox recreate --all --force # Skip confirmation選項:
--all:重新建立所有沙盒容器--session <key>:重新建立特定工作階段的容器--agent <id>:重新建立特定代理程式的容器--browser:僅重新建立瀏覽器容器--force:跳過確認提示
重要: 當下次使用代理程式時,執行環境會自動重新建立。
更新 Docker 映像檔之後
Section titled “更新 Docker 映像檔之後”# Pull new imagedocker pull openclaw-sandbox:latestdocker tag openclaw-sandbox:latest openclaw-sandbox:bookworm-slim
# Update config to use new image# Edit config: agents.defaults.sandbox.docker.image (or agents.list[].sandbox.docker.image)
# Recreate containersopenclaw sandbox recreate --all變更沙盒設定之後
Section titled “變更沙盒設定之後”# Edit config: agents.defaults.sandbox.* (or agents.list[].sandbox.*)
# Recreate to apply new configopenclaw sandbox recreate --all變更 SSH 目標或 SSH 驗證資料後
Section titled “變更 SSH 目標或 SSH 驗證資料後”# Edit config:# - agents.defaults.sandbox.backend# - agents.defaults.sandbox.ssh.target# - agents.defaults.sandbox.ssh.workspaceRoot# - agents.defaults.sandbox.ssh.identityFile / certificateFile / knownHostsFile# - agents.defaults.sandbox.ssh.identityData / certificateData / knownHostsData
openclaw sandbox recreate --all對於核心 ssh 後端,recreate 會刪除 SSH 目標上每個範圍 (per-scope) 的遠端工作區根目錄。下次執行時會從本機工作區重新進行初始化 (seed)。
變更 OpenShell 來源、原則或模式後
Section titled “變更 OpenShell 來源、原則或模式後”# Edit config:# - agents.defaults.sandbox.backend# - plugins.entries.openshell.config.from# - plugins.entries.openshell.config.mode# - plugins.entries.openshell.config.policy
openclaw sandbox recreate --all對於 OpenShell remote 模式,recreate 會刪除該範圍的標準遠端工作區。下次執行時會從本機工作區重新進行初始化。
變更 setupCommand 後
Section titled “變更 setupCommand 後”openclaw sandbox recreate --all# or just one agent:openclaw sandbox recreate --agent family僅針對特定 Agent
Section titled “僅針對特定 Agent”# Update only one agent's containersopenclaw sandbox recreate --agent alfred為何需要此操作?
Section titled “為何需要此操作?”問題: 當您更新沙箱設定時:
- 現有的執行時 (runtimes) 會繼續使用舊設定執行
- 執行時只有在閒置 24 小時後才會被清除
- 經常使用的 Agent 會讓舊的執行時無限期保持運作
解決方案: 使用 openclaw sandbox recreate 強制移除舊的執行時。當下次需要時,它們會自動以目前的設定重新建立。
提示:比起手動針對特定後端進行清理,建議優先使用 openclaw sandbox recreate。
它使用 Gateway 的執行時註冊表,並可避免當範圍/工作階段金鑰變更時發生不一致。
沙箱設定位於 ~/.openclaw/openclaw.json 下的 agents.defaults.sandbox 中 (每個 Agent 的覆寫值放在 agents.list[].sandbox):
{ "agents": { "defaults": { "sandbox": { "mode": "all", // off, non-main, all "backend": "docker", // docker, ssh, openshell "scope": "agent", // session, agent, shared "docker": { "image": "openclaw-sandbox:bookworm-slim", "containerPrefix": "openclaw-sbx-", // ... more Docker options }, "prune": { "idleHours": 24, // Auto-prune after 24h idle "maxAgeDays": 7, // Auto-prune after 7 days }, }, }, },}