OpenClaw 多Agent调用 + 沙箱控制 + 指定目录挂载踩坑记录

背景

我有两台电脑上部署了 OpenClaw,其中一台是 M3 的工作电脑,是我日常在用的,属于人机混用电脑,对安全有一定要求,所以需要按照具体情况把一些 Agent 放进沙箱里。我的配置大概有以下三个需求:

  1. 指定 Agent 在沙箱中工作,避免错误对我的工作电脑产生较大影响。
  2. 指定一些非 workspace 目录挂载在 Agent 沙箱里,让他帮我操作,把 Agent 的影响范围固定在某些目录。
  3. 多 Agent 调用,不想在 QQ 或者飞书上配置一堆机器人,每次对他们直接下达任务。任务派发和统计应当由总控 Agent 处理。

具体配置

配置前吐槽

OpenClaw 作为 vibe coding 的标志性产物,文档远没有跟上产品更新。文档乱的就是一坨屎。我几年前在朋友圈吐槽过阿里云的文档,现在来看 OpenClaw 的说明文档对比当年阿里云那些产品文档,有过之而无不及。

Agent 沙箱配置与挂载

Agent 如何配置沙箱在官方文档中有明确的记载和解释:
https://docs.openclaw.ai/zh-CN/gateway/sandboxing

我当前的配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"id": "richeng",
"name": "richeng",
"workspace": "/Users/chezi/.openclaw/workspace-richeng",
"agentDir": "/Users/chezi/.openclaw/agents/richeng/agent",
"model": "kimi-coding/k2p5",
"sandbox": {
"mode": "non-main",
"scope": "agent",
"docker": {
"dangerouslyAllowExternalBindSources": true,
"binds": [
"/Users/chezi/Library/Mobile Documents/iCloud~md~obsidian/Documents/main/02-Areas/生活管理:/mnt/obsidian-life:rw"
]
}
},
"tools": {
"allow": ["read","write","edit","exec","apply_patch"],
"deny": ["process","browser"]
}
}

这里比较坑的是挂载 workspace 外的目录。关键参数是 dangerouslyAllowExternalBindSources,你如果不配置这个参数,沙箱中的 agent 无法操作 workspace 以外的目录。

这个设定就是脱裤子放屁——workspace 的目录根本不需要自己去配置挂载,默认就挂载了。需要配置挂载目录的时候,一定是 workspace 之外的目录。dangerouslyAllowExternalBindSources 默认是 false,你不修改就无法挂载你指定的目录。

但是 dangerouslyAllowExternalBindSources 在沙箱文档中没有提及,根本不知道如何开启。他在安全相关的文档中。

而且在报错的时候提示信息里面不会告诉你这个参数,他的报错信息如下:

1
Agent failed before reply: Sandbox security: bind mount "/Users/chezi/Library/Mobile Documents/iCloudmdobsidian/Documents/main/02-Areas/生活管理:/mnt/obsidian-life:rw" source "/Users/chezi/Library/Mobile Documents/iCloudmdobsidian/Documents/main/02-Areas/生活管理" is outside allowed roots (/Users/chezi/.openclaw/workspace-richeng). Use a dangerous override only when you fully trust this runtime

就这报错信息,鬼知道怎么开放?鬼知道配置项是 dangerouslyAllowExternalBindSources?这要搁以前,找这玩意真的全凭运气,我果断就脱坑了。

我怎么找到的?我踏马让 OpenClaw 自己去翻自己源码找到的 T_T。真的是 AI 的问题只能 AI 解决。这可能也是未来编程领域的常态,我们维护文档的速度都抵不上 AI 开发的速度了。

Agent 间调用

这玩意更离谱,我至今没找到官方文档如何配置 Agent 间调用。网络上一大把的方案都是曲线救国,通过一堆飞书机器人来跟每个 Agent 通信。

但是正确的方式应当是交给总控 Agent,由 Agent 来进行任务分配和调度,最后与你直接进行交付。

还是无意间在知乎上找到的文章才找到了正确的方案:https://zhuanlan.zhihu.com/p/2021981811933193407

关键的配置有两处,一处是在主 Agent(main)的地方设置可以调用的子 Agent:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"agents": {
"list": [
{
"id": "main",
"name": "小爪",
"subagents": {
"allowAgents": ["richeng", "coder"]
},
"model": "moonshot/kimi-k2.5"
}
]
}
}

另一处是要在 tools 设置允许 Agent 之间通信:

1
2
3
4
5
6
7
8
{
"tools": {
"agentToAgent": {
"enabled": true,
"allow": ["main", "richeng", "coder"]
}
}
}

配置参考

下边是具体的配置文件,查看更全面一些,意义参考:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{
"agents": {
"list": [
{
"id": "main",
"name": "小爪",
"subagents": {
"allowAgents": ["richeng", "coder"]
},
"model": "moonshot/kimi-k2.5"
},
{
"id": "richeng",
"name": "richeng",
"workspace": "/Users/chezi/.openclaw/workspace-richeng",
"agentDir": "/Users/chezi/.openclaw/agents/richeng/agent",
"model": "kimi-coding/k2p5",
"sandbox": {
"mode": "non-main",
"scope": "agent",
"docker": {
"dangerouslyAllowExternalBindSources": true,
"binds": [
"/Users/chezi/Library/Mobile Documents/iCloud~md~obsidian/Documents/main/02-Areas/生活管理:/mnt/obsidian-life:rw"
]
}
},
"tools": {
"allow": ["read","write","edit","exec","apply_patch"],
"deny": ["process","browser"]
}
}
]
},
"tools": {
"agentToAgent": {
"enabled": true,
"allow": ["main", "richeng", "coder"]
}
}
}