Sandbox CLI
管理基于 Docker 的沙盒容器,用于智能体的隔离执行?
概述
OpenClaw 可以在隔离的 Docker 容器中运行智能体以确保安全。sandbox 命令帮助你管理这些容器,尤其是在更新或配置更改后?
命令
openclaw sandbox explain
检?*有效?*沙盒模式/范围/工作区访问、沙盒工具策略和提权门禁(带有修复配置键路径)?
openclaw sandbox explain
openclaw sandbox explain --session agent:main:main
openclaw sandbox explain --agent work
openclaw sandbox explain --json
openclaw sandbox list
列出所有沙盒容器及其状态和配置?
openclaw sandbox list
openclaw sandbox list --browser # 仅列出浏览器容器
openclaw sandbox list --json # JSON 输出
*输出包括?
- 容器名称和状态(运行/停止?
- Docker 镜像及是否与配置匹配
- 存在时间(创建以来的时间?
- 空闲时间(上次使用以来的时间?
- 关联的会?智能?
openclaw sandbox recreate
删除沙盒容器以使用更新的镜像/配置强制重新创建?
openclaw sandbox recreate --all # 重新创建所有容?
openclaw sandbox recreate --session main # 特定会话
openclaw sandbox recreate --agent mybot # 特定智能?
openclaw sandbox recreate --browser # 仅浏览器容器
openclaw sandbox recreate --all --force # 跳过确认
*选项?
--all:重新创建所有沙盒容?--session <key>:重新创建特定会话的容器--agent <id>:重新创建特定智能体的容?--browser:仅重新创建浏览器容?--force:跳过确认提?
*重要? 容器在下一次使用智能体时会自动重新创建?
用例
更新 Docker 镜像?
# 拉取新镜?
docker pull openclaw-sandbox:latest
docker tag openclaw-sandbox:latest openclaw-sandbox:bookworm-slim
# 更新配置以使用新镜像
# 编辑配置:agents.defaults.sandbox.docker.image(或 agents.list[].sandbox.docker.image?
# 重新创建容器
openclaw sandbox recreate --all
更改沙盒配置?
# 编辑配置:agents.defaults.sandbox.*(或 agents.list[].sandbox.*?
# 重新创建以应用新配置
openclaw sandbox recreate --all
更改 setupCommand ?
openclaw sandbox recreate --all
# 或仅一个智能体?
openclaw sandbox recreate --agent family
仅针对特定智能体
# 仅更新一个智能体的容?
openclaw sandbox recreate --agent alfred
为什么需要这个?
*问题? 当你更新沙盒 Docker 镜像或配置时?
- 现有容器继续使用旧设置运?
- 容器仅在空闲 24 小时后才被清?
- 经常使用的智能体会无限期地保持旧容器运行
*解决方案? 使用 openclaw sandbox recreate 强制删除旧容器。它们会在下次需要时使用当前设置自动重新创建?
提示:优先使?openclaw sandbox recreate 而不是手?docker rm。它使用网关的容器命名方式,避免范围/会话键更改时的不匹配?
配置
沙盒设置位于 ~/.openclaw/openclaw.json 中的 agents.defaults.sandbox 下(每个智能体覆盖放?agents.list[].sandbox):
{
"agents": {
"defaults": {
"sandbox": {
"mode": "all", // off, non-main, all
"scope": "agent", // session, agent, shared
"docker": {
"image": "openclaw-sandbox:bookworm-slim",
"containerPrefix": "openclaw-sbx-",
// ... 更多 Docker 选项
},
"prune": {
"idleHours": 24, // 空闲 24 小时后自动清?
"maxAgeDays": 7, // 7 天后自动清理
},
},
},
},
}
另请参阅
- Sandbox 文档
- 智能体配置
- Doctor 命令 - 检查沙盒设?