跳到主要内容

沙箱 CLI

管理基于 Docker 的沙箱容器,用于隔离代理的执行。

概览

为了安全起见,Clawdbot 可以在隔离的 Docker 容器中运行代理。sandbox 命令可以帮助您管理这些容器,特别是在更新或配置更改之后。

命令

clawdbot sandbox explain

检查 有效 的沙箱模式/范围/工作区访问权限、沙箱工具策略和提权门控(带有修复配置键路径)。

clawdbot sandbox explain
clawdbot sandbox explain --session agent:main:main
clawdbot sandbox explain --agent work
clawdbot sandbox explain --json

clawdbot sandbox list

列出所有沙箱容器及其状态和配置。

clawdbot sandbox list
clawdbot sandbox list --browser # 仅列出浏览器容器
clawdbot sandbox list --json # JSON 输出

输出包括:

  • 容器名称和状态(运行中/已停止)
  • Docker 镜像以及是否与配置匹配
  • 存活时间(自创建以来的时间)
  • 空闲时间(自上次使用以来的时间)
  • 关联的会话/代理

clawdbot sandbox recreate

删除沙箱容器,以强制使用更新后的镜像/配置重新创建。

clawdbot sandbox recreate --all                # 重新创建所有容器
clawdbot sandbox recreate --session main # 特定会话
clawdbot sandbox recreate --agent mybot # 特定代理
clawdbot sandbox recreate --browser # 仅浏览器容器
clawdbot sandbox recreate --all --force # 跳过确认

选项:

  • --all:重新创建所有沙箱容器
  • --session <key>:重新创建特定会话的容器
  • --agent <id>:重新创建特定代理的容器
  • --browser:仅重新创建浏览器容器
  • --force:跳过确认提示

重要提示: 容器将在下次使用代理时自动重新创建。

使用场景

更新 Docker 镜像后

# 拉取新镜像
docker pull clawdbot-sandbox:latest
docker tag clawdbot-sandbox:latest clawdbot-sandbox:bookworm-slim

# 更新配置以使用新镜像
# 编辑配置:agents.defaults.sandbox.docker.image (或 agents.list[].sandbox.docker.image)

# 重新创建容器
clawdbot sandbox recreate --all

更改沙箱配置后

# 编辑配置:agents.defaults.sandbox.* (或 agents.list[].sandbox.*)

# 重新创建以应用新配置
clawdbot sandbox recreate --all

更改 setupCommand 后

clawdbot sandbox recreate --all
# 或仅针对一个代理:
clawdbot sandbox recreate --agent family

仅针对特定代理

# 仅更新一个代理的容器
clawdbot sandbox recreate --agent alfred

为什么需要这个?

问题: 当您更新沙箱 Docker 镜像或配置时:

  • 现有容器继续使用旧设置运行
  • 容器仅在空闲 24 小时后才会被清理
  • 经常使用的代理会无限期地保持旧容器运行

解决方案: 使用 clawdbot sandbox recreate 强制删除旧容器。它们将在下次需要时使用当前设置自动重新创建。

提示:建议使用 clawdbot sandbox recreate 而不是手动执行 docker rm。它使用网关的容器命名方式,并能避免在范围/会话键更改时出现不匹配。

配置

沙箱设置位于 ~/.clawdbot/clawdbot.jsonagents.defaults.sandbox 下(每个代理的覆盖设置位于 agents.list[].sandbox 中):

{
"agents": {
"defaults": {
"sandbox": {
"mode": "all", // off, non-main, all
"scope": "agent", // session, agent, shared
"docker": {
"image": "clawdbot-sandbox:bookworm-slim",
"containerPrefix": "clawdbot-sbx-"
// ... 更多 Docker 选项
},
"prune": {
"idleHours": 24, // 空闲 24 小时后自动清理
"maxAgeDays": 7 // 7 天后自动清理
}
}
}
}
}

另请参阅