#安全问题
1 messages · Page 1 of 1 (latest)
可以,这个需求可以做到,而且是 OpenClaw 推荐的安全路线。
你这 4 条目标本质上就是:“全程 sandbox + 精确挂载 + 禁止 elevated 逃逸”。
先给你一套可直接落地的方案(JSON5):
{
agents: {
list: [
{
id: "secure-agent",
default: false,
workspace: "/home/you/secure-agent/workspace",
sandbox: {
mode: "all", // 所有会话都进沙箱
scope: "agent", // 每个 agent 一个沙箱
workspaceAccess: "rw", // 对自己的 workspace 完整读写
docker: {
image: "openclaw-sandbox:bookworm-slim",
readOnlyRoot: true, // 容器根文件系统只读
network: "none", // 禁网(按需改 bridge)
capDrop: ["ALL"],
// 你指定的可访问目录(仅这些被映射进容器)
binds: [
"/home/you/projectA:/allowed/projectA:rw",
"/home/you/dataB:/allowed/dataB:rw"
]
}
},
tools: {
// 禁止 sandbox 逃逸
elevated: { enabled: false },
// 只给文件+命令行能力
sandbox: {
tools: {
allow: ["group:runtime", "group:fs", "group:sessions"],
deny: ["browser", "canvas", "nodes", "gateway", "cron"]
}
}
}
}
]
},
// 全局再关一次 elevated,避免误开
tools: {
elevated: { enabled: false }
}
}
这套配置如何对应你的 4 个目标
- agent 对自己 workspace 完全读写
workspaceAccess: "rw"+workspace指定路径。
-
agent 对指定文件夹完全读写
通过docker.binds显式挂载:rw。 -
不能访问其他文件夹
未挂载的 host 路径在容器里不可见;同时elevated关掉,不能跳出沙箱到 host 执行。 -
有命令行能力但不能影响指定目录外
group:runtime给exec/process;命令只在容器里跑。
对 host 的持久影响只会落在/workspace和你挂载的/allowed/*这些映射路径。
应用与验证(建议)
pnpm openclaw --version
pnpm openclaw config validate
pnpm openclaw gateway restart
pnpm openclaw sandbox recreate --agent secure-agent
pnpm openclaw sandbox explain --agent secure-agent
pnpm openclaw sandbox list
一个关键注意点(很重要)
如果你把 bind 源路径设在 workspace 之外,某些版本会触发“outside allowed roots”保护。
这时你会看到需要 break-glass 选项:dangerouslyAllowExternalBindSources。
建议优先不要开,优先把可访问目录规划到受控路径里;要开的话我可以帮你做最小风险版本。
文档(官方):
- https://docs.openclaw.ai/help/faq
- https://docs.openclaw.ai/gateway/sandboxing
- https://docs.openclaw.ai/gateway/sandbox-vs-tool-policy-vs-elevated
- https://docs.openclaw.ai/gateway/security
如果你把你的真实目录结构贴出来(workspace 路径 + 想授权的文件夹),我可以直接给你一份可粘贴到 openclaw.json 的最终配置。
1:我使用windows11,在wsl里(ubuntu)配置的openclaw,但是我要映射回我windows系统的D盘的某个文件夹作为挂载目录
2:我需要能有命令行操作权限
3:我尝试按照这个配置,但是agent自己连自己的核心文件IDENTITY都无法正常修改
你这个场景很典型(WSL + Windows 盘挂载),先给你一个能稳定跑的排查+配置方案。
先麻烦你回我这两个输出(版本很关键):
pnpm openclaw --version
pnpm openclaw sandbox explain --agent secure-agent
你现在遇到的“连 IDENTITY 都改不了”,通常就 3 个原因:
workspaceAccess不是rw(是ro/none)- sandbox 工具策略里把
write/edit/apply_patch禁了 tools.fs.workspaceOnly=true,但IDENTITY.md不在当前 workspace 路径内
WSL 挂载 Windows D 盘的正确写法
Windows D:\xxx 在 WSL 里要写成:
/mnt/d/xxx
比如你要挂载 D:\AI\data,写:
/mnt/d/AI/data:/allowed/data:rw
推荐配置(先用这个最小可用版)
{
agents: {
list: [
{
id: "secure-agent",
workspace: "/mnt/d/OpenClaw/workspace", // 你的工作区(含 IDENTITY.md)
sandbox: {
mode: "all",
scope: "agent",
workspaceAccess: "rw",
docker: {
readOnlyRoot: true,
network: "none",
capDrop: ["ALL"],
// 如果要额外挂载 D 盘目录:
binds: ["/mnt/d/OpenClaw/shared:/allowed/shared:rw"],
// 如果出现 outside allowed roots 报错,再开这个(break-glass)
// dangerouslyAllowExternalBindSources: true
}
},
tools: {
elevated: { enabled: false },
sandbox: {
tools: {
allow: ["group:runtime", "group:fs", "group:sessions"],
deny: ["browser", "canvas", "nodes", "gateway", "cron"]
}
}
}
}
]
},
tools: {
elevated: { enabled: false }
}
}
应用后执行
pnpm openclaw config validate
pnpm openclaw gateway restart
pnpm openclaw sandbox recreate --agent secure-agent
pnpm openclaw sandbox explain --agent secure-agent
如果你愿意,我下一条可以直接按你的真实路径(D:\...)给你生成一份可直接粘贴的完整 openclaw.json 片段。
另外把你现在的 agents.list[].tools 和 agents.list[].sandbox 发我,我可以直接指出是哪一行导致 IDENTITY 不能改。
{
"id": "qianxue",
"default": true,
"name": "浅雪",
"workspace": "/home/daidaipig/.openclaw/workspace-qianxue",
"agentDir": "/home/daidaipig/.openclaw/agents/qianxue/agent",
"model": "google/gemini-3.1-flash-lite-preview",
"sandbox": {
"mode": "all",
"docker": {
"binds": ["/mnt/d/study/OB_files:/study/OB_files:rw"],
"dangerouslyAllowExternalBindSources": true
}
},
"tools": {
"profile": "coding",
"allow": ["group:fs", "group:runtime"],
"exec": {
"host": "sandbox",
"security": "full",
"ask": "off"
}
}
}
你这个配置里最关键的问题我看到了:少了 workspaceAccess: "rw"。
sandbox.workspaceAccess 默认是 "none",所以 agent 看不到/改不了自己 workspace 里的 IDENTITY.md,这正好解释你的现象。
直接改成这样(核心差异)
"sandbox": {
"mode": "all",
"scope": "agent",
"workspaceAccess": "rw",
"docker": {
"binds": ["/mnt/d/study/OB_files:/study/OB_files:rw"],
"dangerouslyAllowExternalBindSources": true,
"readOnlyRoot": true,
"network": "none",
"capDrop": ["ALL"]
}
}
另外建议加一条,防止 exec 逃逸到 host:
"tools": {
"profile": "coding",
"allow": ["group:fs", "group:runtime"],
"elevated": { "enabled": false },
"exec": {
"host": "sandbox",
"security": "full",
"ask": "off"
}
}
你现在要做的 4 步(很重要)
pnpm openclaw config validate
pnpm openclaw sandbox recreate --agent qianxue --force
pnpm openclaw gateway restart
pnpm openclaw sandbox explain --agent qianxue
改了 sandbox 配置后,不
recreate的话,旧容器还在,改动可能不生效。
再检查一个常见坑
如果你全局开了 tools.fs.workspaceOnly=true,那 /study/OB_files 这种 workspace 外路径会被 fs 工具拒绝。
先看一下:
pnpm openclaw config get tools.fs.workspaceOnly --json
如果是 true 且你确实要访问 /study/OB_files,就需要改成 false(或把目标目录并入 workspace 设计)。
你这份配置已经接近正确了,核心就是 workspaceAccess + recreate。
如果你愿意,我可以按你完整 openclaw.json 给你做一版“最小改动补丁”。
"readOnlyRoot": true,
"network": "none",
"capDrop": ["ALL"]
这三行是什么意思
这三行是沙箱的“硬化”选项,作用分别是:
-
"readOnlyRoot": true
容器的根文件系统设为只读。
也就是除了你挂载的目录(/workspace、binds)和临时目录(如/tmp)外,其他地方不能写。
✅ 防止 agent 乱改系统文件
⚠️ 也会导致apt install这类操作失败(除非你专门放开) -
"network": "none"
容器禁网。
agent 在 sandbox 里不能访问互联网(不能curl、pip install、联网下载等)。
✅ 安全性高
⚠️ 需要联网任务时要改成bridge或自定义网络 -
"capDrop": ["ALL"]
去掉容器进程所有 Linux capabilities(额外特权能力)。
✅ 降低提权/逃逸风险
⚠️ 某些依赖特殊权限的命令会不可用(大多数日常文件和命令不受影响)
你可以把这三项理解成:只让 agent 在你授权的目录里干活,且尽量“手无寸铁、不能上网”。
如果我要能联网,那么应当如何修改network选项
如果你要让 sandbox 能联网,把:
"network": "none"
改成:
"network": "bridge"
这是最常用、最简单的联网模式。
更稳一点的做法是用自定义 bridge 网络(便于后续做规则):
"network": "openclaw-sandbox-net"
先创建一次网络:
docker network create openclaw-sandbox-net
改完后要让容器重建才生效:
pnpm openclaw config validate
pnpm openclaw sandbox recreate --agent qianxue --force
pnpm openclaw gateway restart
补充两点:
network: "host"会被安全策略拦截(不建议)。network: "container:xxx"默认也会被拦截,除非开 break-glass 选项。
如果你愿意,我可以再给你一版“可联网但尽量安全”的完整 sandbox 配置模板。
介绍一下bridge网络
可以,给你一个实用版的 bridge 网络说明(结合你这个 sandbox 场景):
bridge 是什么
bridge 是 Docker 默认的虚拟交换网络。
容器接到一个私有网段(常见 172.x.x.x),通过宿主机做 NAT 出网。
在 OpenClaw sandbox 里用 bridge,意味着什么
-
✅ 能联网:可以
curl、pip install、访问 API -
✅ 默认隔离:容器不直接暴露到外网
-
✅ 容器互通:同一个 bridge 网络里的容器彼此可访问(按容器名/IP)
-
⚠️ 风险比
none高:agent 可访问互联网,提示注入后的外联风险增加 -
⚠️ 仍可能访问内网资源(取决于路由和防火墙)
和其他模式对比(你最关心)
network: "none"
最安全,完全断网network: "bridge"
折中方案:可联网 + 仍有容器隔离(最常用)network: "host"
共享宿主网络,风险高,OpenClaw 默认拦截
你的场景建议
你要命令行 + 读写 + 适度安全,推荐:
network: "bridge"
- 同时保留:
readOnlyRoot: true、capDrop: ["ALL"] - 继续只挂载白名单目录(
binds)
这样是“可用性和安全性”比较平衡的一档。
我发现你总是能获得正确且可靠的信息。能不能告诉我你的这些关于openclaw的知识是从哪里获得的?是本地知识库还是网络搜索?如何搜索?因为我自己的agent总是告诉我过时且无用的信息。你使用什么模型?
你这个问题问得非常好,核心点就是:先本地、再源码、最后才网络。
我拿 OpenClaw 信息的优先级基本是:
- 本地文档(最高优先)
先看 FAQ + 配置/安全文档(避免“记忆里猜键名”) - 本地源码校验
用rg在docs/和src/里查真实字段和行为 - 官网文档镜像
本地不够再看 docs 站 - 网络搜索(最后)
只用于补充,不作为配置键名的唯一依据
你可以给自己的 agent 加一套“防过时”流程(非常有效):
# 1) 先确认版本
pnpm openclaw --version
# 2) 同步本地仓库
cd ~/openclaw-ref && git pull
# 3) 先查 FAQ(强制)
rg -n "sandbox|bind|workspaceAccess|tools\\.fs\\.workspaceOnly" docs/help/faq.md
# 4) 再查配置参考和源码
rg -n "workspaceAccess|dangerouslyAllowExternalBindSources|tools\\.sandbox\\.tools" docs src
再让 agent 回答时必须:
- 给出文档路径/链接
- 给出实际配置键名
- 不确定就明确说“不确定,需要继续查”
关于你问的“我用什么模型”:
这个我不直接报运行时模型(这类信息经常失真,也不利于你复现)。
你要选模型,最稳是看:
- 模型文档:https://docs.openclaw.ai/concepts/models
- 社区实时经验:
#models频道(这个比静态回答更新得快)
如果你愿意,我可以下一条直接给你一个“防过时 AGENTS.md 模板”,专门约束 agent 回答 OpenClaw 时必须先查本地 docs+源码。
你的文档从哪里来?
主要来自这几个地方(按优先级):
-
本地仓库文档(首选)
~/openclaw-ref/docs/
例如:~/openclaw-ref/docs/help/faq.md -
本地源码(用于核对真实配置键和行为)
~/openclaw-ref/src/ -
官方文档站(镜像)
https://docs.openclaw.ai -
GitHub 源仓库(最终权威)
https://github.com/openclaw/openclaw
如果本地仓库没同步,信息就会旧,所以我一般会先建议先 git pull 再查。
帮我生成一段git pull的指令只用于获得github上的文档
可以,用这个最简命令(已有仓库时):
cd ~/openclaw-ref && git pull --ff-only origin main
如果你想只同步 docs 目录(稀疏检出),用这一段:
mkdir -p ~/openclaw-docs && cd ~/openclaw-docs
git init
git remote add origin https://github.com/openclaw/openclaw.git
git sparse-checkout init --cone
git sparse-checkout set docs
git pull --ff-only origin main
以后更新文档只需在 ~/openclaw-docs 里再跑一次:
git pull --ff-only origin main
发现 write 和 edit 这两个工具在当前沙箱环境里报了 Python 依赖错误
这个报错基本已经定位了:
write/edit 在当前实现里会调用 Python helper,你的 sandbox 容器里大概率没有 python3(或被只读/权限限制导致不可用)。
最稳方案(推荐)是换成带常用依赖的沙箱镜像:
- 构建 common 镜像(含
python3)
bash ~/openclaw-ref/scripts/sandbox-common-setup.sh
- 配置里改:
"sandbox": {
"mode": "all",
"workspaceAccess": "rw",
"docker": {
"image": "openclaw-sandbox-common:bookworm-slim",
"readOnlyRoot": true
}
}
- 重建沙箱:
pnpm openclaw sandbox recreate --agent qianxue --force
pnpm openclaw gateway restart
如果你不想换镜像,也可以临时用 setupCommand 装 Python(但安全性会弱一点):
"docker": {
"network": "bridge",
"readOnlyRoot": false,
"user": "0:0",
"setupCommand": "apt-get update && apt-get install -y python3"
}
这个方式依赖可联网+root+writable root。
你之前的readOnlyRoot: true会让 apt 安装失败。
再补一个排查点:如果你设置过 OPENCLAW_PINNED_WRITE_PYTHON,确认它在沙箱里也存在,否则也会报 Python 依赖错误。
如果还不行,把完整报错贴我,我给你精确到哪一步失败。
如果python报错,会影响什么功能?
如果是 Python 依赖报错(sandbox pinned mutation helper),主要影响的是文件“修改类”能力:
会受影响
writeeditapply_patch- 以及底层的
mkdir / rename / remove(凡是走文件变更 helper 的)
也就是说:改 IDENTITY.md、写代码文件、打补丁这类操作会失败。
通常不受影响
read(只读)- 纯命令执行本身(
exec)
但如果任务流程依赖
write/edit,整体任务还是会卡住。
一句话总结:
Python 报错 = 读可能还行,写改删会大面积失效。
所以你看到 write/edit 出问题是完全符合现象的。
会不会是我的wsl里本身就没有python
有可能,但更常见不是 WSL 本身,而是sandbox 容器里没有 Python。
你现在是 sandbox.mode: "all",write/edit 主要在容器里跑。
所以判断顺序是:
- 先看 WSL 主机有没有:
python3 --version
- 再看 sandbox 容器有没有(这个更关键):
pnpm openclaw sandbox list
# 拿到容器名后
docker exec -it <sandbox容器名> python3 --version
如果主机有、容器没有,就会出现你现在这种 write/edit 报 Python 依赖错。
这种情况要么换 openclaw-sandbox-common:bookworm-slim,要么在 sandbox 镜像里安装 python3。
📦 Sandbox Runtimes:
openclaw-sbx-agent-qianxue-821db691
Status: 🟢 running
Image: openclaw-sandbox:bookworm-slim ✓
Backend: docker
Age: 17h 6m
Idle: 16m 59s
Session: agent:qianxue
Total: 1 (1 running)
daidaipig@localhost:~$ docker exec -it openclaw-sbx-agent-qianxue-821db691 python3 --version
OCI runtime exec failed: exec failed: unable to start container process: exec: "python3": executable file not found in $PATH
完美,已经定位了 ✅
你这个报错就是根因:当前沙箱镜像 openclaw-sandbox:bookworm-slim 里没有 python3。
推荐修复(不降低安全性)
用带 Python 的官方 common 沙箱镜像:
- 构建镜像
bash ~/openclaw-ref/scripts/sandbox-common-setup.sh
- 把 agent 配置改成:
"sandbox": {
"mode": "all",
"workspaceAccess": "rw",
"docker": {
"image": "openclaw-sandbox-common:bookworm-slim",
"binds": ["/mnt/d/study/OB_files:/study/OB_files:rw"],
"dangerouslyAllowExternalBindSources": true,
"readOnlyRoot": true,
"network": "bridge",
"capDrop": ["ALL"]
}
}
- 重建沙箱(关键)
pnpm openclaw sandbox recreate --agent qianxue --force
pnpm openclaw gateway restart
- 验证
pnpm openclaw sandbox list
docker exec -it $(docker ps --filter name=openclaw-sbx-agent-qianxue --format '{{.Names}}' | head -1) python3 --version
如果你想,我下一条可以直接给你一份完整可粘贴的 qianxue 最终配置块(包含你 D 盘挂载 + 可联网 + write/edit 可用 + 安全边界)。
如果这次修好啦,麻烦把解决消息标记一下 ✅(右键消息 → Apps → Mark Solution),方便后面的人搜到。
daidaipig@localhost:~$ bash ~/openclaw-ref/scripts/sandbox-common-setup.sh
bash: /home/daidaipig/openclaw-ref/scripts/sandbox-common-setup.sh: No such file or directory
这个报错说明你本机没有 ~/openclaw-ref 这个仓库目录,不是脚本本身有问题 👍
你可以这样做:
方案 A(推荐):先拉源码再跑脚本
git clone https://github.com/openclaw/openclaw ~/openclaw-ref
bash ~/openclaw-ref/scripts/sandbox-common-setup.sh
如果你已经有仓库但路径不是这个,先找一下:
find ~ -type f -name sandbox-common-setup.sh 2>/dev/null
然后用找到的完整路径执行。
方案 B(不依赖脚本,直接临时修)
在 sandbox.docker 里加:
"network": "bridge",
"readOnlyRoot": false,
"user": "0:0",
"setupCommand": "apt-get update && apt-get install -y python3"
然后:
pnpm openclaw sandbox recreate --agent qianxue --force
pnpm openclaw gateway restart
如果你愿意,我可以根据你当前安装方式(pnpm openclaw --version + which openclaw)给你一条最短路径命令,不走弯路。
我是直接用curl -fsSL https://openclaw.ai/install.sh | bash命令拉取的openclaw,不是源码安装、
明白,这就对上了:你是 installer 安装,不带源码目录,所以没有 scripts/sandbox-common-setup.sh 很正常。
不过没关系,有两条路:
路线 1(推荐,安全性更好)
即使不是源码安装,也可以单独 clone 一份仓库只拿脚本建镜像,不影响你现有安装。
git clone https://github.com/openclaw/openclaw ~/openclaw-build
bash ~/openclaw-build/scripts/sandbox-common-setup.sh
然后把 agent 配置改成:
"docker": {
"image": "openclaw-sandbox-common:bookworm-slim",
"readOnlyRoot": true,
"network": "bridge",
"capDrop": ["ALL"],
"binds": ["/mnt/d/study/OB_files:/study/OB_files:rw"],
"dangerouslyAllowExternalBindSources": true
}
最后重建:
pnpm openclaw sandbox recreate --agent qianxue --force
pnpm openclaw gateway restart
路线 2(快,但安全性稍弱)
不建新镜像,直接在容器创建时装 python:
"docker": {
"image": "openclaw-sandbox:bookworm-slim",
"network": "bridge",
"readOnlyRoot": false,
"user": "0:0",
"setupCommand": "apt-get update && apt-get install -y python3",
"binds": ["/mnt/d/study/OB_files:/study/OB_files:rw"],
"dangerouslyAllowExternalBindSources": true
}
然后同样 recreate + restart。
你这个场景我建议走路线 1,后续更稳。
如果你愿意,我可以直接给你一份 qianxue 的完整最终配置块(可直接粘贴)。
daidaipig@localhost:~/.openclaw/src$ git clone https://github.com/openclaw/openclaw ~/openclaw-build
Cloning into '/home/daidaipig/openclaw-build'...
remote: Enumerating objects: 384145, done.
remote: Counting objects: 100% (551/551), done.
remote: Compressing objects: 100% (281/281), done.
remote: Total 384145 (delta 356), reused 292 (delta 270), pack-reused 383594 (from 2)
Receiving objects: 100% (384145/384145), 412.76 MiB | 10.51 MiB/s, done.
Resolving deltas: 100% (251761/251761), done.
daidaipig@localhost:~/.openclaw/src$ bash ~/openclaw-build/scripts/sandbox-common-setup.sh
Building openclaw-sandbox-common:bookworm-slim with: curl wget jq coreutils grep nodejs npm python3 git ca-certificates golang-go rustc cargo unzip pkg-config libasound2-dev build-essential file
[+] Building 0.1s (1/1) FINISHED docker:default
=> [internal] load build definition from Dockerfile.sandbox-common 0.0s
=> => transferring dockerfile: 2B 0.0s
ERROR: failed to build: failed to solve: failed to read dockerfile: open Dockerfile.sandbox-common: no such file or directory
你这个报错原因很明确:
脚本里用了相对路径 -f Dockerfile.sandbox-common,所以必须在仓库根目录执行。
你刚才在 ~/.openclaw/src 下运行了 ~/openclaw-build/scripts/...,当前目录不对,所以找不到 Dockerfile。
直接这样跑就行:
cd ~/openclaw-build
ls Dockerfile.sandbox-common
bash scripts/sandbox-common-setup.sh
如果 ls 能看到文件,后面就会正常构建。
构建完别忘了:
-
配置 image 改成
openclaw-sandbox-common:bookworm-slim -
重建沙箱
pnpm openclaw sandbox recreate --agent qianxue --force
pnpm openclaw gateway restart
你这次已经离成功很近了。
介绍一下这些操作的原理
好问题。你这套操作背后的原理,核心是这 6 点:
- 为什么会报 Python 错
- 在 sandbox 模式下,
write/edit不是直接“裸写文件”,而是走一个安全的 mutation helper(做路径边界校验、原子写等)。 - 这个 helper 在你当前版本里依赖
python3。 - 你的镜像
openclaw-sandbox:bookworm-slim默认没有python3,所以写改类工具失败。
- 为什么换 common 镜像能修
openclaw-sandbox-common:bookworm-slim是在基础沙箱镜像上预装常用依赖(含 python3)。- 所以 helper 能启动,
write/edit/apply_patch恢复正常。
- 为什么要在 repo 根目录执行脚本
sandbox-common-setup.sh里用的是相对路径-f Dockerfile.sandbox-common。- Docker 会在“当前工作目录”找这个文件,不是按脚本所在目录找。
- 所以必须
cd ~/openclaw-build后再执行。
- 为什么要
sandbox recreate
- 你改的是“未来容器配置/镜像”。
- 已在运行的容器不会自动换镜像。
recreate= 删除旧沙箱容器并按新配置重建,改动才真正生效。
- 为什么还要 restart gateway
- 网关需要重新加载配置和运行态,确保 agent 会话都走新沙箱参数。
- 有些配置可热加载,但这里重启最稳妥。
- 为什么这样还能保证安全边界
- 访问范围由三层共同约束:
workspaceAccess: rw(只给 workspace)docker.binds(只暴露你白名单目录)elevated: false+exec host: sandbox(不允许逃逸到 host)- 所以 agent 有命令行和写文件能力,但只能在你映射进来的范围内活动。
你现在其实已经把“可用性 + 安全性”的关键路径打通了。
单纯把这些步骤的操作过程每一步进行解释
当然可以,下面只讲“操作过程”,一步一步解释,不扩展别的:
1) git clone ... ~/openclaw-build
**你在做什么:**把 OpenClaw 源码下载到本地。
**为什么做:**你是 installer 安装,没有脚本文件;这个步骤是为了拿到 scripts/sandbox-common-setup.sh 和 Dockerfile.sandbox-common。
**结果:**本地多了 ~/openclaw-build 目录。
2) cd ~/openclaw-build
**你在做什么:**切换到仓库根目录。
**为什么做:**后面的构建脚本用相对路径找 Dockerfile,必须在仓库根目录执行。
**结果:**脚本能正确找到 Dockerfile.sandbox-common。
3) bash scripts/sandbox-common-setup.sh
**你在做什么:**构建一个新的沙箱镜像。
**为什么做:**默认镜像没有 python3,这个 common 镜像会预装 python3 等常用依赖。
**结果:**本机 Docker 里出现 openclaw-sandbox-common:bookworm-slim。
4) 在 openclaw.json 里把 sandbox image 改成 common 镜像
**你在做什么:**告诉 OpenClaw:以后新建沙箱用新镜像。
**为什么做:**让 write/edit 在有 python3 的环境里运行。
**结果:**配置层面已切换,但旧容器还没变。
5) pnpm openclaw sandbox recreate --agent qianxue --force
**你在做什么:**删除并重建该 agent 的沙箱容器。
**为什么做:**已运行容器不会自动换镜像,必须重建。
**结果:**新容器按新镜像+新参数启动。
6) pnpm openclaw gateway restart
**你在做什么:**重启网关进程。
**为什么做:**确保运行态和配置同步,避免旧状态残留。
**结果:**后续会话稳定使用新沙箱配置。
7) 验证(sandbox list / docker exec ... python3 --version)
**你在做什么:**确认容器确实是新镜像且 python3 可用。
**为什么做:**这是判断问题是否真正修复的最终证据。
**结果:**若能输出 Python 版本,write/edit 的依赖问题就已解决。
如果你想,我可以把这 7 步整理成一份“可复制执行清单”(只保留命令 + 一行注释)。
openclaw-sbx-agent-qianxue-821db691
Status: 🟢 running
Image: openclaw-sandbox:bookworm-slim ✓
Backend: docker
Age: 31s
Idle: 31s
Session: agent:qianxue
agent回复:
唔……看来还是不太行呢,报错信息依然是那个老样子。(叹气)
看来这边的环境还没配置好 Python 相关的依赖
你这个输出已经说明核心问题了:
新容器还是 openclaw-sandbox:bookworm-slim,没有切到 openclaw-sandbox-common。
所以不是 “recreate 失败”,而是“配置没生效/没写到正在运行的 config”。
按这个顺序做,一次性定位:
# 1) 先确认新镜像确实存在
docker image ls | grep openclaw-sandbox-common
# 2) 看当前配置实际值(默认 + qianxue)
pnpm openclaw config get agents.defaults.sandbox.docker.image --json
pnpm openclaw config get agents.list[0].sandbox.docker.image --json
# 3) 强制写入(先写 defaults,再写 agent 覆盖)
pnpm openclaw config set agents.defaults.sandbox.docker.image "openclaw-sandbox-common:bookworm-slim"
pnpm openclaw config set agents.list[0].sandbox.docker.image "openclaw-sandbox-common:bookworm-slim"
# 4) 检查 CLI 和 service 是否在用同一个 config
pnpm openclaw config file
pnpm openclaw gateway status
如果 gateway status 里出现 Config (cli) 和 Config (service) 不同,再执行:
pnpm openclaw gateway install --force
然后重建:
pnpm openclaw sandbox recreate --agent qianxue --force
pnpm openclaw gateway restart
pnpm openclaw sandbox list
你最终要看到的是:
Image: openclaw-sandbox-common:bookworm-slim
如果你愿意,贴一下这三条输出我帮你秒判是哪一层没生效:
pnpm openclaw config filepnpm openclaw gateway statuspnpm openclaw config get agents.list[0].sandbox.docker.image --json
总结我的配置中所有的知识点:
{
"id": "qianxue",
"name": "浅雪",
"workspace": "/home/daidaipig/.openclaw/workspace/qianxue",
"agentDir": "/home/daidaipig/.openclaw/agents/qianxue/agent",
"model": "zai/glm-5.1",
"sandbox": {
"mode": "all",
"workspaceAccess": "rw",
"scope": "agent",
"docker": {
"binds": ["/mnt/d/study/OB_files:/study/OB_files:rw"],
"dangerouslyAllowExternalBindSources": true,
"readOnlyRoot": true,
"image": "openclaw-sandbox-common:bookworm-slim",
"network": "none",
"capDrop": ["ALL"]
}
},
"tools": {
"profile": "coding",
"allow": ["group:fs", "group:runtime"],
"elevated": {
"enabled": false
},
"exec": {
"host": "sandbox",
"security": "full",
"ask": "off"
}
}
}
这份配置已经非常专业了。我按“知识点 + 作用 + 安全含义”给你完整总结:
1) Agent 基本身份与存储
-
id: "qianxue"
Agent 唯一标识,用于路由、会话、沙箱命名等。 -
name: "浅雪"
展示名,不影响权限。 -
workspace: "/home/.../workspace/qianxue"
这个 agent 的工作区根目录(记忆文件、AGENTS/SOUL/IDENTITY 等都在这里)。 -
agentDir: "/home/.../agents/qianxue/agent"
这个 agent 的状态目录(会话、认证等)。
model: "zai/glm-5.1"
此 agent 默认模型路由。
2) Sandboxing(核心安全边界)
-
sandbox.mode: "all"
所有会话都进沙箱,不走宿主机直跑。 -
sandbox.workspaceAccess: "rw"
给 agent 对自己 workspace 完整读写权限(你之前改不了 IDENTITY 的关键修复点)。 -
sandbox.scope: "agent"
每个 agent 一套沙箱容器/环境,隔离性好于 shared。
3) Docker 沙箱细项
-
binds: ["/mnt/d/study/OB_files:/study/OB_files:rw"]
把 Windows D 盘目录(WSL 路径)映射到容器内,允许读写。 -
dangerouslyAllowExternalBindSources: true
允许绑定 workspace 之外目录(比如/mnt/d/...)。
⚠️ 这是 break-glass 开关,必要但要谨慎。 -
readOnlyRoot: true
容器根文件系统只读,降低误改系统文件风险。 -
image: "openclaw-sandbox-common:bookworm-slim"
使用带常用依赖(含 Python)的镜像,解决write/edit的 Python 依赖问题。 -
network: "none"
沙箱断网,安全性高(但不能联网下载/调用外部 API)。
capDrop: ["ALL"]
去掉 Linux 特权能力,降低提权/逃逸面。
4) Tool 权限模型
-
tools.profile: "coding"
以 coding profile 为基础工具集。 -
tools.allow: ["group:fs", "group:runtime"]
最终允许:文件工具 + 运行时工具(exec/process 等)。 -
tools.elevated.enabled: false
禁止 exec 逃逸出沙箱到 host(非常关键)。 -
tools.exec.host: "sandbox"
明确命令只在沙箱跑,不去 gateway/node host。
tools.exec.security: "full" + ask: "off"
不做审批拦截,命令可直接执行。
✅ 可用性高
⚠️ 如果被提示注入,agent 在“你授权目录内”可做较强操作
5) 你的 4 个目标映射结果
- 工作区完全读写 →
workspaceAccess: rw✅ - 指定目录读写 →
binds + rw✅ - 其他目录不可访问 → 沙箱 + 白名单挂载 + 无 elevated ✅(强隔离)
- 可命令行但不影响外部目录 →
exec host=sandbox+elevated=false+ 挂载边界 ✅
整体评价:这已经是“高可用 + 高安全”的配置。
如果你后续要联网,只需把 network: "none" 改成 bridge,其余安全边界可以保持不变。
我在创建新agent的时候这句话是什么意思:
Copy auth profiles from "main"?
这句话的意思是:
要不要把 main 这个 agent 的认证凭据(auth profiles)复制到新 agent。
具体来说会复制什么?
- 各模型/Provider 的登录信息或 API key 配置(保存在 auth profiles)
- 让新 agent 立刻能用和
main一样的模型权限
不会复制什么?
- 不会复制聊天会话历史
- 不会复制 workspace 文件内容
- 不会把两个 agent 合并成一个
什么时候选 Yes
- 你只是想快速创建新 agent,并且它也需要用同一套模型凭据
什么时候选 No
- 你要做权限隔离(比如这个 agent 不该访问某些 provider 或账号)
- 你想给它单独登录/单独 key
简化理解:
Yes = 继承 main 的“钥匙串”,不是继承 main 的“记忆和文件”。
"docker": {
"binds": [
"/mnt/d/study/OB_files:/study/OB_files:rw",
"/mnt/d/CH3SH:/d/CH3SH:rw"
],
"dangerouslyAllowExternalBindSources": true,
"readOnlyRoot": true,
"image": "openclaw-sandbox-common:bookworm-slim",
"network": "none",
"capDrop": ["ALL"]
}
为什么agent看不到这个新的/mnt/d/CH3SH文件夹