Files
bot/docs/zh-CN/cli/sandbox.md
zeekay 6e661b15d3 rebrand: complete OpenClaw→Hanzo Bot cleanup across 424 files
- Rename lobster extension → flow (dir, types, env vars, docs)
- LOBSTER_* env vars → BOT_FLOW_* / BOT_*
- 🦞 → 🤖 everywhere (src, docs, skills, zh-CN)
- docs.bot.ai → docs.hanzo.bot
- github.com/bot/bot → github.com/hanzoai/bot
- @bot/* → @hanzo/bot-* (npm scope)
- ~/.bot/ → ~/.hanzo/bot/ (config paths)
- discord.gg/hanzo → discord.gg/XthHQQj (real Hanzo Discord)
- clawhub.com → skills.hanzo.bot
- ClawDock → BotDock in shell helpers
- EXFOLIATE lore → Hanzo Bot branding in all locales
- LOBSTER_PALETTE → BOT_PALETTE, LOBSTER_ASCII → BOT_ASCII
2026-02-13 13:22:53 -08:00

4.3 KiB

read_when, status, summary, title, x-i18n
read_when status summary title x-i18n
You are managing sandbox containers or debugging sandbox/tool-policy behavior. active 管理沙箱容器并检查生效的沙箱策略 沙箱 CLI
generated_at model provider source_hash source_path workflow
2026-02-03T07:45:18Z claude-opus-4-5 pi 6e1186f26c77e188206ce5e198ab624d6b38bc7bb7c06e4d2281b6935c39e347 cli/sandbox.md 15

沙箱 CLI

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

概述

Hanzo Bot 可以在隔离的 Docker 容器中运行智能体以确保安全。sandbox 命令帮助你管理这些容器,特别是在更新或配置更改后。

命令

hanzo-bot sandbox explain

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

hanzo-bot sandbox explain
hanzo-bot sandbox explain --session agent:main:main
hanzo-bot sandbox explain --agent work
hanzo-bot sandbox explain --json

hanzo-bot sandbox list

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

hanzo-bot sandbox list
hanzo-bot sandbox list --browser  # List only browser containers
hanzo-bot sandbox list --json     # JSON output

输出包括:

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

hanzo-bot sandbox recreate

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

hanzo-bot sandbox recreate --all                # Recreate all containers
hanzo-bot sandbox recreate --session main       # Specific session
hanzo-bot sandbox recreate --agent mybot        # Specific agent
hanzo-bot sandbox recreate --browser            # Only browser containers
hanzo-bot sandbox recreate --all --force        # Skip confirmation

选项:

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

重要: 容器会在智能体下次使用时自动重新创建。

使用场景

更新 Docker 镜像后

# Pull new image
docker pull bot-sandbox:latest
docker tag bot-sandbox:latest bot-sandbox:bookworm-slim

# Update config to use new image
# Edit config: agents.defaults.sandbox.docker.image (or agents.list[].sandbox.docker.image)

# Recreate containers
hanzo-bot sandbox recreate --all

更改沙箱配置后

# Edit config: agents.defaults.sandbox.* (or agents.list[].sandbox.*)

# Recreate to apply new config
hanzo-bot sandbox recreate --all

更改 setupCommand 后

hanzo-bot sandbox recreate --all
# or just one agent:
hanzo-bot sandbox recreate --agent family

仅针对特定智能体

# Update only one agent's containers
hanzo-bot sandbox recreate --agent alfred

为什么需要这个?

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

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

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

提示:优先使用 hanzo-bot sandbox recreate 而不是手动 docker rm。它使用 Gateway 网关的容器命名规则,避免在作用域/会话键更改时出现不匹配。

配置

沙箱设置位于 ~/.hanzo/bot/bot.json 的 agents.defaults.sandbox 下(每个智能体的覆盖设置在 agents.list[].sandbox 中):

{
  "agents": {
    "defaults": {
      "sandbox": {
        "mode": "all", // off, non-main, all
        "scope": "agent", // session, agent, shared
        "docker": {
          "image": "bot-sandbox:bookworm-slim",
          "containerPrefix": "bot-sbx-",
          // ... more Docker options
        },
        "prune": {
          "idleHours": 24, // Auto-prune after 24h idle
          "maxAgeDays": 7, // Auto-prune after 7 days
        },
      },
    },
  },
}

另请参阅