多智能体沙箱与工具配置
概述
多智能体设置中的每个智能体现在都可以拥有自己的:
- 沙箱配置(
agents.list[].sandbox覆盖agents.defaults.sandbox) - 工具限制(
tools.allow/tools.deny,加上agents.list[].tools)
这允许你运行具有不同安全配置文件的多个智能体:
- 拥有完全访问权限的个人助手
- 具有受限工具的家庭/工作智能体
- 在沙箱中面向公众的智能体
setupCommand 属于 sandbox.docker(全局或每个智能体),并在容器创建时运行一次。
身份验证是每个智能体独立的:每个智能体从其自己的 agentDir 身份验证存储中读取,位于:
~/.openclaw/agents/<agentId>/agent/auth-profiles.json凭证不在智能体之间共享。永远不要在智能体之间重用 agentDir。 如果你想共享凭证,将 auth-profiles.json 复制到另一个智能体的 agentDir 中。
有关沙箱在运行时的行为方式,请参阅 沙箱。 有关调试"为什么被阻止?",请参阅 沙箱 vs 工具策略 vs 提升模式 和 openclaw sandbox explain。
配置示例
示例 1: 个人 + 受限家庭智能体
{
"agents": {
"list": [
{
"id": "main",
"default": true,
"name": "Personal Assistant",
"workspace": "~/.openclaw/workspace",
"sandbox": { "mode": "off" }
},
{
"id": "family",
"name": "Family Bot",
"workspace": "~/.openclaw/workspace-family",
"sandbox": {
"mode": "all",
"scope": "agent"
},
"tools": {
"allow": ["read"],
"deny": ["exec", "write", "edit", "apply_patch", "process", "browser"]
}
}
]
},
"bindings": [
{
"agentId": "family",
"match": {
"provider": "whatsapp",
"accountId": "*",
"peer": {
"kind": "group",
"id": "120363424282127706@g.us"
}
}
}
]
}结果:
main智能体:在主机上运行,完全工具访问权限family智能体:在 Docker 中运行(每个智能体一个容器),仅read工具
示例 2: 共享沙箱的工作智能体
{
"agents": {
"list": [
{
"id": "personal",
"workspace": "~/.openclaw/workspace-personal",
"sandbox": { "mode": "off" }
},
{
"id": "work",
"workspace": "~/.openclaw/workspace-work",
"sandbox": {
"mode": "all",
"scope": "shared",
"workspaceRoot": "/tmp/work-sandboxes"
},
"tools": {
"allow": ["read", "write", "apply_patch", "exec"],
"deny": ["browser", "gateway", "discord"]
}
}
]
}
}示例 2b: 全局编码配置文件 + 仅消息智能体
{
"tools": { "profile": "coding" },
"agents": {
"list": [
{
"id": "support",
"tools": { "profile": "messaging", "allow": ["slack"] }
}
]
}
}结果:
- 默认智能体获得编码工具
support智能体仅支持消息(+ Slack 工具)
示例 3: 每个智能体不同的沙箱模式
{
"agents": {
"defaults": {
"sandbox": {
"mode": "non-main", // Global default
"scope": "session"
}
},
"list": [
{
"id": "main",
"workspace": "~/.openclaw/workspace",
"sandbox": {
"mode": "off" // Override: main never sandboxed
}
},
{
"id": "public",
"workspace": "~/.openclaw/workspace-public",
"sandbox": {
"mode": "all", // Override: public always sandboxed
"scope": "agent"
},
"tools": {
"allow": ["read"],
"deny": ["exec", "write", "edit", "apply_patch"]
}
}
]
}
}配置优先级
当全局(agents.defaults.*)和智能体特定(agents.list[].*)配置都存在时:
沙箱配置
智能体特定设置覆盖全局设置:
agents.list[].sandbox.mode > agents.defaults.sandbox.mode
agents.list[].sandbox.scope > agents.defaults.sandbox.scope
agents.list[].sandbox.workspaceRoot > agents.defaults.sandbox.workspaceRoot
agents.list[].sandbox.workspaceAccess > agents.defaults.sandbox.workspaceAccess
agents.list[].sandbox.docker.* > agents.defaults.sandbox.docker.*
agents.list[].sandbox.browser.* > agents.defaults.sandbox.browser.*
agents.list[].sandbox.prune.* > agents.defaults.sandbox.prune.*注意:
agents.list[].sandbox.{docker,browser,prune}.*为该智能体覆盖agents.defaults.sandbox.{docker,browser,prune}.*(当沙箱范围解析为"shared"时被忽略)。
工具限制
过滤顺序为:
- 工具配置文件(
tools.profile或agents.list[].tools.profile) - 提供者工具配置文件(
tools.byProvider[provider].profile或agents.list[].tools.byProvider[provider].profile) - 全局工具策略(
tools.allow/tools.deny) - 提供者工具策略(
tools.byProvider[provider].allow/deny) - 智能体特定工具策略(
agents.list[].tools.allow/deny) - 智能体提供者策略(
agents.list[].tools.byProvider[provider].allow/deny) - 沙箱工具策略(
tools.sandbox.tools或agents.list[].tools.sandbox.tools) - 子智能体工具策略(
tools.subagents.tools,如适用)
每个级别都可以进一步限制工具,但不能授予早期级别拒绝的工具。 如果设置了 agents.list[].tools.sandbox.tools,它将替换该智能体的 tools.sandbox.tools。 如果设置了 agents.list[].tools.profile,它将覆盖该智能体的 tools.profile。 提供者工具键接受 provider(例如 google-antigravity)或 provider/model(例如 openai/gpt-5.2)。
工具组(简写)
工具策略(全局、智能体、沙箱)支持 group:* 条目,可扩展为多个具体工具:
group:runtime:exec,bash,processgroup:fs:read,write,edit,apply_patchgroup:sessions:sessions_list,sessions_history,sessions_send,sessions_spawn,session_statusgroup:memory:memory_search,memory_getgroup:ui:browser,canvasgroup:automation:cron,gatewaygroup:messaging:messagegroup:nodes:nodesgroup:openclaw: 所有内置 OpenClaw 工具(不包括提供者插件)
提升模式
tools.elevated 是全局基线(基于发送者的允许列表)。agents.list[].tools.elevated 可以进一步限制特定智能体的提升模式(两者都必须允许)。
缓解模式:
- 拒绝不受信任智能体的
exec(agents.list[].tools.deny: ["exec"]) - 避免将路由到受限智能体的发送者加入允许列表
- 如果只想要沙箱执行,则全局禁用提升模式(
tools.elevated.enabled: false) - 为敏感配置文件的每个智能体禁用提升模式(
agents.list[].tools.elevated.enabled: false)
从单智能体迁移
之前(单智能体):
{
"agents": {
"defaults": {
"workspace": "~/.openclaw/workspace",
"sandbox": {
"mode": "non-main"
}
}
},
"tools": {
"sandbox": {
"tools": {
"allow": ["read", "write", "apply_patch", "exec"],
"deny": []
}
}
}
}之后(具有不同配置文件的多智能体):
{
"agents": {
"list": [
{
"id": "main",
"default": true,
"workspace": "~/.openclaw/workspace",
"sandbox": { "mode": "off" }
}
]
}
}遗留 agent.* 配置由 openclaw doctor 迁移;今后优先使用 agents.defaults + agents.list。
工具限制示例
只读智能体
{
"tools": {
"allow": ["read"],
"deny": ["exec", "write", "edit", "apply_patch", "process"]
}
}安全执行智能体(不修改文件)
{
"tools": {
"allow": ["read", "exec", "process"],
"deny": ["write", "edit", "apply_patch", "browser", "gateway"]
}
}仅通信智能体
{
"tools": {
"allow": ["sessions_list", "sessions_send", "sessions_history", "session_status"],
"deny": ["exec", "write", "edit", "apply_patch", "read", "browser"]
}
}常见陷阱:"非主"
agents.defaults.sandbox.mode: "non-main" 基于 session.mainKey(默认 "main"), 而不是智能体 ID。群组/频道会话总是获得自己的密钥,因此它们 被视为非主并将被沙箱化。如果你希望智能体永不 沙箱化,设置 agents.list[].sandbox.mode: "off"。
测试
配置多智能体沙箱和工具后:
检查智能体解析:
execopenclaw agents list --bindings验证沙箱容器:
execdocker ps --filter "name=openclaw-sbx-"测试工具限制:
- 发送需要受限工具的消息
- 验证智能体无法使用被拒绝的工具
监控日志:
exectail -f "${OPENCLAW_STATE_DIR:-$HOME/.openclaw}/logs/gateway.log" | grep -E "routing|sandbox|tools"
故障排除
尽管设置了 mode: "all",智能体未被沙箱化
- 检查是否有覆盖它的全局
agents.defaults.sandbox.mode - 智能体特定配置优先,因此设置
agents.list[].sandbox.mode: "all"
尽管设置了拒绝列表,工具仍然可用
- 检查工具过滤顺序:全局 → 智能体 → 沙箱 → 子智能体
- 每个级别只能进一步限制,不能授予回来
- 通过日志验证:
[tools] filtering tools for agent:${agentId}
容器未按智能体隔离
- 在智能体特定沙箱配置中设置
scope: "agent" - 默认为
"session",每个会话创建一个容器