2026年,AI Agent 的权限越来越大——读写文件、调用API、操作数据库。但安全防护却几乎为零。Deno 刚开源的 Claw Patrol 终于解决了这个问题。
为什么 Agent 安全是 2026 年最被低估的问题
想象一个场景:你给 AI Agent 配置了 GitHub Token,让它帮你管理代码仓库。Agent 在某个推理步骤中"决定"把 Token 发送给一个外部 API 来"验证是否有效"。几小时后,你的仓库被清空了。
这不是假设——而是随着 Agent 自主性增强、权限范围扩大后真实可能发生的事。
2026 年 6 月,AI Agent 的三大安全现实:
- 权限膨胀:现代 Agent(Hermes Agent、OpenClaw、Claude Code)普遍拥有文件读写、Shell 执行、网络访问权限
- 黑箱决策:Agent 的推理过程不透明,你无法预判它会用哪些外部服务
- API Token 暴露:Agent 的环境变量中通常包含多个 API Key,一旦泄漏后果严重
Claw Patrol 的发布时机恰到好处。 这个由 Deno 团队出品的安全工具,专为 OpenClaw Agent 设计,提供进程级出站防火墙——你可以精确定义 Agent 能访问哪些外部服务。
Claw Patrol 是什么?
Claw Patrol(https://github.com/denoland/clawpatrol)是一个 Deno 编写的进程级出站防火墙,专为 OpenClaw Agent 设计。核心能力:
- 进程级拦截:在 Agent 进程的网络层设置防火墙规则
- 白名单/黑名单模式:定义哪些域名/IP Agent 可以(或不可以)访问
- 协议级别控制:HTTP、HTTPS、WebSocket、gRPC 等协议可独立配置
- Deno 原生:无需额外依赖,Deno 运行时自带权限系统
HN 社区反应:Show HN 获得 21 points,评论中普遍认为"Agent 安全是下一波创业机会"。
为什么选 Deno 生态?
Deno 的安全模型天然适合 Agent 防火墙场景:
# Deno 运行时的权限控制示例
deno run --allow-net=api.github.com,api.openai.com agent.ts
这个设计哲学直接启发了 Claw Patrol——默认全部拒绝,只开放必要权限。
快速上手:5 分钟部署 Claw Patrol
前置条件
- Deno 2.0+(安装:
curl -fsSL https://deno.land/install.sh | sh) - 已运行的 OpenClaw Agent 实例
Step 1:安装 Claw Patrol
# 克隆仓库
git clone https://github.com/denoland/clawpatrol.git
cd clawpatrol
# 安装依赖(Deno 自动处理)
deno cache main.ts
Step 2:创建配置文件
创建 clawpatrol.json:
{
"mode": "whitelist",
"rules": [
{
"type": "domain",
"pattern": "api.openai.com",
"action": "allow",
"protocols": ["https"],
"note": "GPT-4 API 调用"
},
{
"type": "domain",
"pattern": "api.anthropic.com",
"action": "allow",
"protocols": ["https"],
"note": "Claude API 调用"
},
{
"type": "domain",
"pattern": "api.github.com",
"action": "allow",
"protocols": ["https"],
"note": "GitHub 操作"
},
{
"type": "ip_range",
"pattern": "10.0.0.0/8",
"action": "allow",
"protocols": ["*"],
"note": "内网服务"
}
],
"default_action": "deny",
"log_level": "warn"
}
Step 3:启动防火墙
# 以代理模式启动 Claw Patrol
deno run --allow-net --allow-read --allow-env main.ts \
--config clawpatrol.json \
--target-port 8080
此时,所有 Agent 发出的网络请求都会先经过 Claw Patrol 的规则引擎过滤。未在白名单中的域名将被静默拒绝。
Step 4:验证防火墙生效
# 测试允许的请求(应该成功)
curl -x http://localhost:8080 https://api.github.com
# 测试拒绝的请求(应该被拦截)
curl -x http://localhost:8080 https://evil-api.example.com
# → 403 Forbidden (blocked by Claw Patrol)
实战配置:生产环境安全策略
策略一:最小权限白名单(推荐)
{
"mode": "whitelist",
"rules": [
{
"type": "domain",
"pattern": "api.openai.com",
"action": "allow",
"protocols": ["https"]
},
{
"type": "domain",
"pattern": "api.anthropic.com",
"action": "allow",
"protocols": ["https"]
},
{
"type": "domain",
"pattern": "api.github.com",
"action": "allow",
"protocols": ["https"]
},
{
"type": "domain",
"pattern": "raw.githubusercontent.com",
"action": "allow",
"protocols": ["https"],
"note": "下载 Skill/依赖"
}
],
"default_action": "deny"
}
适用场景:已知 Agent 只需要访问特定 API 的场景(如只调用 OpenAI + GitHub)。
策略二:黑名单拦截高危域名
{
"mode": "blacklist",
"rules": [
{
"type": "domain",
"pattern": "*.ngrok.io",
"action": "deny",
"note": "隧道穿透服务"
},
{
"type": "domain",
"pattern": "pastebin.com",
"action": "deny",
"note": "数据外泄渠道"
},
{
"type": "ip_range",
"pattern": "0.0.0.0/0",
"action": "allow",
"protocols": ["https"],
"note": "其他 HTTPS 放行"
}
],
"default_action": "allow"
}
适用场景:Agent 需要广泛网络访问,但需要拦截已知的高危目标。
策略三:分段隔离(企业级)
{
"mode": "whitelist",
"rules": [
{
"type": "domain",
"pattern": "*.internal.corp.com",
"action": "allow",
"note": "企业内部服务"
}
],
"agents": {
"code-reviewer": {
"rules": [
{"type": "domain", "pattern": "api.github.com", "action": "allow"}
]
},
"data-analyst": {
"rules": [
{"type": "domain", "pattern": "api.openai.com", "action": "allow"},
{"type": "domain", "pattern": "analytics-db.internal", "action": "allow"}
]
}
},
"default_action": "deny"
}
适用场景:多个 Agent 实例,每个有不同的外部访问需求。按 Agent 角色分配权限。
进阶:Claw Patrol + Agent-pd 双重防护体系
防火墙只解决了"拦住坏请求"的问题,但还有一个关键需求:事后追溯。
Agent-pd(https://github.com/varmabudharaju/agent-pd)是一个零 Token 开销的 Claude Code 子 Agent 审计日志工具。它记录每个子 Agent 的行为,让你在出问题时能够追溯。
为什么需要双重防护?
| 维度 | Claw Patrol | Agent-pd |
|---|---|---|
| 防护类型 | 预防(事前拦截) | 检测(事后追溯) |
| 作用层 | 网络层 | 行为层 |
| Token 开销 | 零 | 零 |
| 适用工具 | OpenClaw | Claude Code |
组合使用 = 完整安全体系:防火墙拦截恶意请求 + 审计日志追溯可疑行为。
Agent-pd 快速部署
# 安装 Agent-pd
pip install agent-pd
# 启动审计服务(在 Claude Code 运行前)
agent-pd monitor --output ./audit-logs/
# 正常使用 Claude Code
claude --sub-agents 3
# 审计日志自动生成在 ./audit-logs/ 目录
# 格式: {timestamp}-{agent_id}-{action}.json
审计日志示例:
{
"timestamp": "2026-06-10T08:30:00Z",
"agent_id": "sub-agent-3",
"action": "file_write",
"target": "/etc/hosts",
"result": "blocked_by_permission",
"call_stack": ["main-agent→sub-agent-3→file_write"]
}
双防护组合配置脚本
#!/bin/bash
# agent-secure.sh - 启动带双重防护的 Agent
# 1. 启动 Claw Patrol 防火墙(后台)
deno run --allow-net --allow-read clawpatrol/main.ts \
--config clawpatrol-prod.json &
FIREWALL_PID=$!
echo "🔒 Claw Patrol 防火墙已启动 (PID: $FIREWALL_PID)"
# 2. 启动 Agent-pd 审计服务
agent-pd monitor --output ./audit-logs/ &
AUDIT_PID=$!
echo "📋 Agent-pd 审计服务已启动 (PID: $AUDIT_PID)"
# 3. 设置代理环境变量,让 Agent 流量经过防火墙
export HTTP_PROXY=http://localhost:8080
export HTTPS_PROXY=http://localhost:8080
# 4. 启动 Agent(以 OpenClaw 为例)
echo "🤖 启动 OpenClaw Agent..."
openclaw serve
# 5. 清理
kill $FIREWALL_PID $AUDIT_PID
echo "✅ 安全防护服务已关闭"
实战提醒:Agent 安全的三大黄金法则
1. 最小权限原则(POLP)
不要给 Agent 配置 sudo 权限,不要把所有 API Key 都放在同一个 Agent 的环境变量中。每个 Agent 只拥有完成其任务所需的最小权限集合。
2. 网络隔离
✅ 正确做法:
- Agent A(代码审查)→ 只允许 api.github.com
- Agent B(内容生成)→ 只允许 api.openai.com
- Agent C(数据分析)→ 只允许内网数据库
❌ 错误做法:
- 所有 Agent 共享同一个 allow-all 配置
3. 审计日志不能少
即使有防火墙,也必须保留审计日志。安全圈有句老话:"没被入侵是运气好,没发现被入侵是技术差。" Agent-pd 的零 Token 审计让你至少在出事时知道发生了什么。
总结
| 你的情况 | 推荐方案 |
|---|---|
| 刚开始用 Agent,权限简单 | Claw Patrol 白名单模式 |
| Agent 需要广泛网络访问 | Claw Patrol 黑名单模式 |
| 多 Agent 协作 + Claude Code | Claw Patrol + Agent-pd 双重防护 |
| 企业级多 Agent 部署 | 分段隔离 + 集中式审计 |
今日行动:
1. 花 5 分钟部署 Claw Patrol,先用白名单模式保护最关键的 Agent
2. 检查你的 Agent 环境变量,移除不必要的 API Key
3. 如果使用 Claude Code 子 Agent,追加 Agent-pd 审计
Agent 的安全问题不会自动消失——它只会随着 Agent 能力增长而变得更加严重。今天花半小时搭建防护,比明天花三天处理安全事件划算得多。
