Agent 执行沙箱与 Harness 工程
概述
Agent 执行层的基础设施,决定能力边界和安全基线。所有工具调用(代码执行、文件操作、浏览器控制等)经过统一的 Harness 层,实现权限检查、隔离执行、审计日志。
推荐架构:分层渐进式沙箱
| 阶段 | 方案 | 周期 | 覆盖工具 |
|---|---|---|---|
| Phase 1 | Python 级安全包装(路径白名单+rlimit+超时+审计) | 1-2 天 | code_run, file_read/write/patch |
| Phase 2 | macOS sandbox-exec 加固 | 2-3 天 | 全工具 |
| Phase 3 | Docker 容器化(可选) | 2-3 天 | code_run + browser |
工具风险分类
| 风险 | 工具 |
|---|---|
| 🔥 高危 | code_run, web_execute_js, file_write, file_patch |
| ⚠️ 中危 | file_read, web_scan |
| ✅ 低危 | ask_user, checkpoint, no_tool |
Harness 架构:策略模式
class ToolHarness:
def execute(self, tool_name, args):
validated = self._validate(tool_name, args)
self._check_permission(tool_name, validated)
self._check_quota(tool_name)
result = self._sandbox_execute(tool_name, validated)
filtered = self._filter_output(result)
self._audit_log(tool_name, validated, filtered)
return filtered研究方向
- 执行环境架构 — 进程级沙箱 → 容器级 → 函数即服务 → 混合模型
- 安全执行 — 代码沙箱、文件系统隔离、网络白名单、资源限制、超时熔断
- 工具执行管线 — 参数校验→权限检查→配额检查→执行→输出过滤→审计
- MCP 集成 — 9 个原子工具封装为 MCP 工具
- 浏览器 Harness — CDP 封装、视觉感知-操作闭环、反检测策略
- 会话与状态管理 — Agent 生命周期(启动→授权→工作→空闲→休眠→回收)
- 可观测性 — 指标、链路追踪、告警、审计日志
相关页面:agent-safety-boundary agent-memory-system agent-collaboration-communication agent-tool-learning self-verification