OpenClaw Tools 配置详解:全局设置与单Agent配置

  发布时间:2026-04-09 09:43:21   作者:SP八岐大兔   我要评论
文章介绍了OpenClaw的权限配置方法,包括创建Agent、配置权限、使用方法和安全建议,详细说明了Agent的定义、权限配置、沙箱设置等,以及如何通过Web-UI切换Agent,最后提供了适配本地路径和生成快速切换链接的建议,感兴趣的朋友跟随小编一起看看吧

一、核心配置思路

  • Agent1(文件助手):仅开放 group:fs(文件读写),禁止网络/浏览器工具
  • Agent2(GitHub 助手):开放 web_search/web_fetch/browser,禁止本地文件操作
  • 全局 tools 设为最小权限,每个 Agent 单独覆盖权限

二、完整可直接使用的配置

{
  "gateway": {
    "port": 18789,
    "enabled": true
  },
  // 全局默认:最小权限(仅聊天)
  "tools": {
    "profile": "messaging",
    "allow": [],
    "deny": ["*"]
  },
  "agents": {
    "list": [
      // Agent1:本地文件读写专用(id: file-agent)
      {
        "id": "file-agent",
        "name": "本地文件助手",
        "default": true,
        "workspace": "~/.openclaw/workspace-file",
        "tools": {
          "profile": "coding",
          "allow": ["group:fs"],
          "deny": ["group:web", "browser", "web_search", "web_fetch", "exec"]
        },
        "sandbox": {
          "mode": "restricted",
          "filesystem": {
            "read": ["~/Documents", "~/Projects"],	// 只能读这里,为空则禁止
            "write": ["~/Documents/OpenClaw"]		// 只能写这里,为空则禁止
          }
        }
      },
      // Agent2:GitHub/网络访问专用(id: github-agent)
      {
        "id": "github-agent",
        "name": "GitHub 助手",
        "workspace": "~/.openclaw/workspace-github",
        "tools": {
          "profile": "full",
          "allow": ["group:web", "browser", "web_search", "web_fetch"],
          "deny": ["group:fs", "exec", "process"]
        },
        "sandbox": {
          "mode": "strict",
          "filesystem": {
            "read": [],		// 禁止读任何文件
            "write": []		// 禁止写任何文件
          }
        }
      }
    ]
  }
}

三、关键配置说明

1. Agent 定义(agents.list)

  • id:唯一标识(如 file-agent/github-agent),用于切换 Agent
  • workspace:独立工作区,避免文件/会话混淆
  • tools:覆盖全局权限,实现专属能力

2.profile 是做什么的?(超级重要)

profile = 工具预设套餐
OpenClaw 提前给你打包好的工具组合,不用你一个个手动加工具。
4 种官方 profilejson

"profile": "full"       // 全部工具(文件+命令+网络+浏览器)
"profile": "coding"     // 开发工具(文件+编辑+git)
"profile": "messaging"  // 仅聊天(无任何工具权限)
"profile": "minimal"    // 最小工具(仅基础功能)

你写 profile: coding,就等于自动启用一组文件 / 代码工具。不用你在 allow 里手写 read、write、edit…
如果需要自定,则手动根据自定义权限要求配置allow和deny。

3.为什么要加 sandbox?(安全核心)

sandbox = 沙箱 / 权限牢笼
**不加 sandbox 会怎样?**
Agent 能读你整个电脑的文件
能删系统文件、读密码、读桌面所有内容
非常危险 ❌
**加了 sandbox 会怎样?**
只能访问你指定的文件夹
不能越界
不能读系统盘、不能乱删文件
100% 安全 ✅
sandbox 真正作用总结
sandbox 不是可选的,是必须的!
它用来:
限制文件访问范围
限制命令执行权限
限制网络访问范围
防止 Agent 破坏你的电脑

4. Agent1(文件助手)权限

  • "profile": "coding":基础启用文件相关工具
  • "allow": ["group:fs"]:仅允许文件读写(read/write/edit)
  • "deny": [...]:禁止所有网络/执行工具
  • sandbox.filesystem:限制可读写目录(安全加固)

5. Agent2(GitHub 助手)权限

  • "allow": ["group:web", "browser", ...]:开放网页搜索/抓取/浏览器
  • "deny": ["group:fs"]完全禁止本地文件访问
  • sandbox.filesystem: []:无本地文件权限

四、生效与使用步骤

  • 保存配置
    • Windows:%USERPROFILE%\.openclaw\openclaw.json
    • Linux/WSL:~/.openclaw/openclaw.json
  • 重启 Gateway
  • openclaw gateway restart
  • 在 Web-UI 中切换 Agent
    • 访问:http://localhost:18789/?token=你的Token
    • 右上角 Agent 下拉框,选择 本地文件助手GitHub 助手
    • 切换后自动应用对应权限
  • 验证权限
    • 文件 Agent:发送 读取 ~/Documents/test.md → 成功;发送 打开 github.com → 权限不足
    • GitHub Agent:发送 搜索 OpenClaw GitHub → 成功;发送 读取本地文件 → 权限不足

五、安全与扩展建议

  • 最小权限原则:每个 Agent 只开放必要工具
  • 独立工作区workspace 路径必须不同,防止数据交叉
  • 日志审计:在 Web-UI Logs 页查看工具调用记录
  • 按需扩展:如需 Agent2 执行 Git 命令,可添加 "exec" 并限制为 git 命令

需要我帮你把这个配置适配到你的本地路径(比如指定可读写的文件夹),并生成对应的Web-UI 快速切换链接吗?

到此这篇关于OpenClaw Tools 配置详解:全局设置与单Agent配置的文章就介绍到这了,更多相关OpenClaw tools配置内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!

相关文章

最新评论