#本地文件编写
1 messages · Page 1 of 1 (latest)
你这个现象(“agent 写了,但本地 workspace 里看不到 / 写入失败”)在 OpenClaw 里最常见就 4 类原因,我按命中率从高到低给你排查路径:
1) 你以为是“本地”,但 Gateway 实际跑在别的机器上(VPS / remote mode)
文件写入永远发生在 Gateway 所在机器的 workspace 上,不是你发消息的那台电脑。
你可以先确认:
openclaw gateway status
openclaw config get agents.defaults.workspace
如果你是 remote mode(Gateway 在 VPS),那 workspace 也在 VPS。解决方式通常是:
- 想写你电脑上的文件:把 Gateway 跑在你电脑上;或把电脑作为 node 配对后用 node/system.run 去改本地文件(不是 file tools 直接写)
- 或者把你要写的目录通过挂载/同步方式提供给 Gateway
文档:Remote access(远程模式)https://docs.openclaw.ai/gateway/remote.md
FAQ 里也有 “remote mode 下 session/workspace 在哪台机器” 的说明:https://docs.openclaw.ai/help/faq.md
2) 你开了 sandbox,导致写进了 Docker 容器(或者 workspace 是只读)
如果你配置了:
agents.defaults.sandbox.mode: "non-main"(群聊/线程通常是 non-main)或"all"- 且
workspaceAccess不是"rw"
那么write/edit可能会被禁用,或写入的是 sandbox 内的 workspace,你主机的 workspace 不会变。
重点看这两个配置:
openclaw config get agents.defaults.sandbox.mode
openclaw config get agents.defaults.sandbox.workspaceAccess
对应关系(很关键):
workspaceAccess: "none"→ 容器用自己的 workspace(你主机看不到)workspaceAccess: "ro"→ 会挂载但只读(写入会失败)workspaceAccess: "rw"→ 才会把 agent workspace 以读写方式挂进去
文档(含 binds / workspaceAccess):https://docs.openclaw.ai/gateway/sandboxing.md
3) 你把工具权限限制掉了(tools.profile / tools.allow 导致没有文件工具)
如果你设置了 tools.profile: "minimal" 或 "messaging",或者 tools.allow 没包含文件组,那么模型根本拿不到 read/write/edit 工具,自然写不了文件。
检查:
openclaw config get tools.profile
openclaw config get tools.allow
openclaw config get tools.deny
文件工具组是 group:fs(包含 read/write/edit/apply_patch)。文档:
https://docs.openclaw.ai/tools/index.md
4) 你改的是一份 config,但后台 service 跑的是另一份(导致 workspace 不一致)
这会出现“我明明配置了 workspace=A,但实际写到了 B”的错觉。
用这个一眼确认:
openclaw gateway status
重点看里面的 Config (cli) vs Config (service) 是否不一样。
你回我这 5 条信息,我基本就能直接定位
请把输出贴出来(注意别贴 token/密钥):
openclaw --versionopenclaw gateway statusopenclaw config get agents.defaults.workspaceopenclaw config get agents.defaults.sandbox.modeopenclaw config get agents.defaults.sandbox.workspaceAccess以及openclaw config get tools.profile
另外,如果你能贴一下“写文件时 agent 的报错原文/日志片段”,会更快。
我使用的是多智能体功能,我需要检查其中的一个智能体,并且给他开放权限,该怎么办。
多智能体场景下,“给某一个智能体开放权限”,基本就是两件事:
- 确认你当前这条线程/会话到底路由到了哪个 agent
- 只给那个 agent 配置它需要的 tools(尤其是文件相关 group:fs)+(如果启用 sandbox)给它
workspaceAccess: "rw"
下面按步骤来。
1) 先确认要改的是哪个智能体(agent id)
在 Gateway 那台机器上跑:
openclaw agents list
openclaw agents bindings
如果你是在 Discord 线程里操作,也可以在该线程里发 /status(如果你们启用了 slash commands),通常能看到当前用的是哪个 agent。
2) 给这个 agent 开“写 workspace”的最小权限(推荐做法)
编辑 Gateway 机器上的配置文件(JSON5):
- 默认路径:
~/.openclaw/openclaw.json
在目标 agent 的 agents.list[] 里加上(示例:agent id 叫 writer):
{
agents: {
list: [
{
id: "writer",
// 允许文件读写相关工具(最关键)
tools: {
allow: ["group:fs"], // read/write/edit/apply_patch
},
// 如果你开了 sandbox(尤其是 mode:"non-main"/"all"),这行非常关键
sandbox: {
workspaceAccess: "rw", // 否则写入可能在容器里,或直接只读/不可写
},
},
],
},
}
如果你还希望它能在 workspace 里跑命令(比如 pnpm、python、git 等),再加:
tools: { allow: ["group:fs", "group:runtime"] } // exec/bash/process
工具组/权限文档:
- Tools & group:fs/group:runtime: https://docs.openclaw.ai/tools/index.md
- 多智能体 + sandbox + tools 叠加规则: https://docs.openclaw.ai/tools/multi-agent-sandbox-tools.md
- Sandboxing / workspaceAccess: https://docs.openclaw.ai/gateway/sandboxing.md
3) 注意一个“坑”:全局 tools.allow/deny 会卡住你
工具权限过滤是分层的:全局 tools.profile/tools.allow/tools.deny 也会生效,某一层 deny 掉的工具,后面无法“加回来”。
所以如果你发现给 agent 加了 group:fs 还是不行,请你把这几个也贴一下我看(同样别贴 token):
openclaw config get tools.profile
openclaw config get tools.allow
openclaw config get tools.deny
openclaw config get tools.sandbox.tools.allow
openclaw config get tools.sandbox.tools.deny
4) 改完要不要重启?
大部分配置支持热加载,但为了省时间排坑,建议你直接:
openclaw gateway restart
如果你告诉我:你的目标 agent id 是什么、以及你现在全局 tools.profile 是不是 minimal/messaging、还有你 sandbox mode 是不是 non-main,我可以给你一个“最小可用、尽量安全”的精确配置片段。
Runtime: capabilities=none,工具受限(仅部分如 sessions_list/session_status 可用)
C:\Users\39255.openclaw>openclaw config get tools.profile
🦞 OpenClaw 2026.3.2 (85377a2) — The lobster in your shell. 🦞
messaging
C:\Users\39255.openclaw>openclaw config get tools.allow
🦞 OpenClaw 2026.3.2 (85377a2) — Your personal assistant, minus the passive-aggressive calendar reminders.
Config path not found: tools.allow
C:\Users\39255.openclaw>openclaw config get tools.deny
🦞 OpenClaw 2026.3.2 (85377a2) — I can run local, remote, or purely on vibes—results may vary with DNS.
Config path not found: tools.deny
C:\Users\39255.openclaw>openclaw config get tools.sandbox.tools.allow
🦞 OpenClaw 2026.3.2 (85377a2) — Say "stop" and I'll stop—say "ship" and we'll both learn a lesson.
Config path not found: tools.sandbox.tools.allow
C:\Users\39255.openclaw>openclaw config get tools.sandbox.tools.deny
🦞 OpenClaw 2026.3.2 (85377a2) — I've read more man pages than any human should—so you don't have to.
Config path not found: tools.sandbox.tools.deny
你这里已经定位到关键点了:tools.profile = messaging。
messaging 这个 profile 默认不包含文件工具(read/write/edit 都不在里面),所以你的 agent 在运行时看起来就会变成“只能用 sessions_* / session_status 之类的工具”,自然没法写 workspace 文件。
下面给你两种改法(推荐用“只改某一个 agent”的那种)。
方案 A(最快,但会影响所有 agent):全局改成 coding/full
在 Gateway 那台机器上:
openclaw config set tools.profile coding
openclaw gateway restart
coding 会带上 group:fs(文件读写)等工具。
方案 B(推荐):只给某一个 agent 开放文件写入权限
1) 先找到你要改的那个 agent 在 agents.list[] 里的下标
openclaw agents list
openclaw config get agents.list
找到目标 agent 对应的 index(比如是 agents.list[2])。
2) 给这个 agent 单独开 group:fs
最小权限写文件建议这么配:profile 设为 full(不限制),然后用 allow 只放行 group:fs。
openclaw config set agents.list[2].tools.profile full
openclaw config set agents.list[2].tools.allow '["group:fs"]' --strict-json
openclaw gateway restart
如果你还希望它能跑命令(例如在 repo 里跑构建/测试),再加
group:runtime:
["group:fs","group:runtime"]
3) 确认你的 Discord 线程确实路由到了这个 agent
openclaw agents bindings
如果绑定到了别的 agent,你改了也不会生效(线程还是会用原来那个受限 agent)。
额外提醒(很常见)
改完配置后,建议在那个聊天线程里发一次 /new(或重开会话),确保工具列表刷新;否则老 session 里可能还保持“受限工具集”的状态。
如果你把 openclaw agents list 和 openclaw agents bindings 的输出贴出来(打码 token 就行),我可以直接告诉你应该改 agents.list[几]。
我要解决的是白千寻
C:\Users\39255.openclaw>openclaw config get agents.list
🦞 OpenClaw 2026.3.2 (85377a2) — If it works, it's automation; if it breaks, it's a "learning opportunity."
[
{
"id": "qianxue",
"default": true,
"name": "浅雪",
"workspace": "C:\Users\39255\.openclaw\workspace-qianxue",
"agentDir": "C:\Users\39255\.openclaw\agents\qianxue\agent",
"model": "google/gemini-3.1-flash-lite-preview"
},
{
"id": "zhiven",
"name": "知温",
"workspace": "D:\study\OB_files",
"agentDir": "C:\Users\39255\.openclaw\agents\zhiven\agent",
"tools": {
"profile": "coding",
"allow": [
"group:fs",
"group:nodes",
"group:runtime"
]
}
},
{
"id": "linxi",
"name": "林栖",
"workspace": "D:\my files",
"agentDir": "C:\Users\39255\.openclaw\agents\linxi\agent",
"model": "deepseek/deepseek-reasoner"
},
{
"id": "moqing",
"name": "墨清",
"workspace": "C:\Users\39255\.openclaw\workspace-moqing",
"agentDir": "C:\Users\39255\.openclaw\agents\moqing\agent"
},
{
"id": "baiqianxun",
"name": "白千寻",
"workspace": "C:\Users\39255\.openclaw\workspace-baiqianxun",
"agentDir": "C:\Users\39255\.openclaw\agents\baiqianxun\agent",
"model": "xai/grok-4-1-fast-non-reasoning",
"sandbox": {
"workspaceAccess": "rw"
},
"tools": {
"allow": [
"group:fs",
"group:runtime"
]
}
}
]
🦞 OpenClaw 2026.3.2 (85377a2) — It's not "failing," it's "discovering new ways to configure the same thing wrong."
Routing bindings:
- qianxue <- discord accountId=qianxue
- zhiven <- discord accountId=zhiven
- linxi <- discord accountId=linxi
- moqing <- discord accountId=moqing
- baiqianxun <- discord accountId=baiqianxun
你这个配置贴出来以后就非常清楚了:白千寻(baiqianxun)现在之所以还是“工具受限 / 写不了文件”,核心原因是全局 tools.profile = messaging,而白千寻没有覆盖自己的 tools.profile。
tools.allow 只能“继续收紧”,不能把 profile 里本来就没有的工具再加回来。
所以你虽然给白千寻写了:
tools: { allow: ["group:fs","group:runtime"] }
但在 messaging profile 下,group:fs(read/write/edit)根本不会被提供给模型。
你看 zhiven 为啥能用?因为它显式写了 tools.profile: "coding",覆盖了全局。
直接修复(只改白千寻,不动全局)
白千寻在你 agents.list 里是 第 5 个(索引 4),直接设它的 profile:
openclaw config set agents.list[4].tools.profile coding
openclaw gateway restart
(也可以用 full,但 coding 更贴近“需要写文件/跑命令”的场景。)
改完后建议在 Discord 那边对“白千寻”发一次 /new(或重开会话),让工具列表刷新。
验证方法(最简单)
让白千寻写个测试文件,例如 hello.txt,然后你在:
C:\Users\39255\.openclaw\workspace-baiqianxun\
里确认文件是否出现/内容是否正确。
如果你改完 tools.profile 还是“调用了 write 但没落盘”,下一步我会让你贴这两条(判断是不是 sandbox/工作目录/权限问题):
openclaw config get agents.defaults.sandbox.mode
openclaw config get agents.list[4].sandbox
将如何为agent配置权限整理成一份完整的md文件,方便我保存到本地
下面是一份可以直接复制保存的 Markdown 文档(例如保存为 openclaw-agent-permissions.md)。内容面向 OpenClaw 多智能体(multi-agent),重点讲清楚“为什么某个 agent 写不了 workspace / 如何只给某个 agent 开权限”。
# OpenClaw 多智能体:为单个 Agent 配置工具权限(tools)与 Workspace 写入指南
适用版本:OpenClaw 2026.x(本文以 2026.3.x 行为为准)
适用场景:你启用了多智能体(`agents.list`),希望“只给某一个 agent”开放写文件、执行命令等权限,同时尽量不影响其它 agent。
---
## 1. 你要配置的“权限”到底是什么?
在 OpenClaw 里,常说的“权限”通常指 **Agent 能否使用哪些工具(tools)**,例如:
- 文件工具:`read` / `write` / `edit` / `apply_patch`
- 运行命令:`exec` / `process`(以及某些环境里有 `bash`)
- 发消息:`message`
- 浏览器/画布/节点:`browser` / `canvas` / `nodes`
- 会话管理:`sessions_*` / `session_status`
- 记忆检索:`memory_*`
这些工具是否对模型可用,主要由以下三类配置共同决定:
1) **工具白/黑名单**:`tools.profile`、`tools.allow`、`tools.deny`
2) **按 agent 单独覆盖**:`agents.list[i].tools.*`
3) **沙箱(sandbox)执行环境与 workspace 挂载**:`agents.list[i].sandbox.*`、`tools.sandbox.tools.*`
---
## 2. 最重要的规则(很多“写不了文件”的根因)
### 2.1 `tools.profile` 是“基础工具集”,会先把工具砍掉
`tools.profile`(或 `agents.list[i].tools.profile`)会先决定**基础允许哪些工具**:
- `minimal`:只剩 `session_status`
- `messaging`:偏聊天/会话(不包含文件读写)
- `coding`:包含 `group:fs`、`group:runtime` 等(适合写文件/跑命令)
- `full`:不做基础限制(相当于 unset)
**关键点:后续的 allow/deny 只能继续收紧,不能把 profile 已经砍掉的工具“加回来”。**
> 典型坑:全局 `tools.profile = messaging` 时,即使你在某个 agent 里写了 `tools.allow: ["group:fs"]`,也可能仍然拿不到 `write/edit`,因为 profile 阶段已经不提供文件工具了。
> 解决:给该 agent 显式设置 `agents.list[i].tools.profile = "coding"` 或 `"full"`。
---
## 3. Tool Groups(强烈建议用 group:* 配)
OpenClaw 支持工具组(shorthand),常用的有:
- `group:fs`:`read`, `write`, `edit`, `apply_patch`
- `group:runtime`:`exec`, `bash`, `process`
- `group:messaging`:`message`
- `group:nodes`:`nodes`
- `group:web`:`web_search`, `web_fetch`
- `group:ui`:`browser`, `canvas`
- `group:sessions`:`sessions_list`, `sessions_history`, `sessions_send`, `sessions_spawn`, `session_status`
- `group:memory`:`memory_search`, `memory_get`
- `group:openclaw`:所有内置工具(不含 provider 插件工具)
---
## 4. 配置层级与优先级(简化版)
工具限制大致按以下顺序叠加(越往后越“收紧”):
1) Tool profile:`tools.profile` 或 `agents.list[i].tools.profile`
2) 全局 allow/deny:`tools.allow` / `tools.deny`
3) agent allow/deny:`agents.list[i].tools.allow` / `agents.list[i].tools.deny`
4) sandbox allow/deny(仅 sandbox 会话):`tools.sandbox.tools.*` 或 `agents.list[i].tools.sandbox.tools.*`
结论:
- 想“只给某一个 agent 加权限”,最稳妥做法是:**全局保持宽松(或别用 messaging profile),然后在该 agent 上单独收/放工具。**
- 如果你必须全局用 `messaging`,那么该 agent 一定要显式覆盖 `agents.list[i].tools.profile` 为 `coding/full`。
---
## 5. Sandbox 与“写入 workspace 是否落盘”
即使你工具权限开对了,文件写入是否“写到你看到的那个目录”,还取决于是否启用 sandbox,以及 workspace 是否被正确挂载:
### 5.1 常见场景
- 如果启用了 sandbox(例如 `agents.defaults.sandbox.mode = "non-main"`),群聊/线程等 non-main session 可能会进 Docker sandbox。
- 如果 `workspaceAccess` 不是 `"rw"`,可能出现:
- 写入失败(只读)
- 写入发生在容器内部的 workspace,你主机目录看不到(`none`)
### 5.2 关键配置
- `agents.list[i].sandbox.workspaceAccess: "rw"`
让 sandbox 以读写方式挂载该 agent 的 workspace。
---
## 6. 实操:在 Windows 上“只给某个 agent 开写文件权限”
### 6.1 找到配置文件路径
```bash
openclaw config file
6.2 查看所有 agent(含 workspace 路径)
openclaw config get agents.list
确认你要改的 agent 在列表里的 index(例如第 5 个就是 agents.list[4])。
### 6.3 推荐配置(最小:允许写 workspace + 允许跑命令)
假设目标 agent 是 `agents.list[4]`:
1) 让该 agent 使用更合适的 profile(非常关键)
```bash
openclaw config set agents.list[4].tools.profile coding
- 只允许必要工具(建议用 allowlist)
openclaw config set agents.list[4].tools.allow '["group:fs","group:runtime"]' --strict-json
- 如果你启用了 sandbox(或不确定),建议显式给它 rw
openclaw config set agents.list[4].sandbox.workspaceAccess '"rw"' --strict-json
> 注意:`--strict-json` 下字符串要带引号,所以这里用了 `'"rw"'`。
4) 重启 Gateway(或至少重开会话)
```bash
openclaw gateway restart
并在聊天里对该 agent 对应的会话发一次 /new(建议)。
6.4 验证
让 agent 写一个测试文件,例如 hello.txt,然后到该 agent 的 workspace 目录里确认文件是否出现。
## 7. 常用“权限模板”(可直接粘贴到 openclaw.json / 用 config set 写入)
### 7.1 只读 Agent(安全)
```json5
tools: {
profile: "full",
allow: ["read", "session_status"],
}
7.2 只允许写 workspace(不允许运行命令)
tools: {
profile: "full",
allow: ["group:fs", "session_status"],
}
### 7.3 Coding Agent(写文件 + 跑命令)
```json5
tools: {
profile: "coding",
allow: ["group:fs", "group:runtime"],
}
7.4 Messaging-only Agent(只做聊天/转发)
tools: {
profile: "messaging",
}
---
## 8. 安全建议(强烈建议遵循)
- 尽量给 agent “最小权限”:能写文件不代表也要能 `exec`。
- 群聊/不可信输入环境:优先启用 sandbox,并避免开放 `group:runtime`。
- 如果你发现 agent “能写但写不到你看到的目录”,先查:
- 你是否在 remote mode(写入发生在 Gateway 那台机器上)
- 是否启用了 sandbox,且 workspaceAccess 是否为 `rw`
- 该会话是否路由到了你改的那个 agent(bindings 是否正确)
---
## 9. 参考文档(官方)