沙箱安全
Sandbox 的目标是把高风险执行的“爆炸半径”限制在可控范围内。
什么时候需要 Sandbox
- 你允许 Agent 运行带副作用的工具(尤其是
exec) - 你要在远程/生产环境跑 Gateway
- 你希望把网络/文件访问范围收紧到最小
与 Sandbox 强相关的三类边界
- 工具边界:哪些工具可用、需要审批哪些动作
- 资源边界:CPU/内存/超时/并发等限制
- 网络与文件边界:允许访问哪些主机、哪些路径可读写
从哪里开始
- 网关侧入口:Sandboxing
- 工具与权限:工具
- 生产安全边界:Gateway 安全
audit:
enabled: true
output: /var/log/openclaw/audit.log
format: json
events:
- tool_exec
- tool_result
- approval_request
- security_violation实时监控
# 查看工具执行
openclaw logs --filter=tools
# 查看安全事件
openclaw logs --filter=security最佳实践
1. 生产环境使用 Docker
security:
sandbox: docker2. 最小权限原则
permissions:
tool: exec
allowedCommands:
- python # 只允许必要的命令
allowedPaths:
read:
- ~/workspace/**
write:
- ~/workspace/output/**3. 启用审批流程
approvals:
enabled: true
requireApproval:
- rm
- chmod
- sudo4. 定期审计
# 查看审计日志
openclaw audit --last 7d
# 检查安全违规
openclaw audit --violations故障排除
Docker 未运行
# 检查 Docker 状态
docker ps
# 启动 Docker
# macOS
open -a Docker
# Linux
sudo systemctl start docker容器权限问题
# 检查用户权限
whoami
groups
# 添加到 docker 组
sudo usermod -aG docker $USER工具执行超时
sandbox:
resources:
timeout: 600s # 增加超时时间安全检查清单
- 启用 Docker Sandbox
- 配置命令白名单
- 配置路径限制
- 配置网络限制
- 启用审批流程
- 启用审计日志
- 定期审查配置
- 更新 Sandbox 镜像
下一步
- Gateway 安全 - Gateway 安全配置
- 工具系统 - 工具详解
- 故障排除 - 问题排查