沙箱执行 —— 给 AI Agent 一个"安全游乐场",让它尽情发挥但不会搞破坏
OpenClaw Sandbox Execution(沙箱执行)是一种在隔离的、受控的环境中运行 AI Agent 代码和工具调用的安全机制。沙箱就像一个"透明的玻璃房":Agent 可以在里面自由操作,但无法影响到外部系统,即使出了问题也能快速"重置"。
核心价值:让 Agent 敢于尝试,同时保证系统安全。
| 层级 | 隔离内容 | 实现方式 | 安全级别 |
|---|---|---|---|
| 文件系统隔离 | 只能访问指定目录 | chroot/namespace | ⭐⭐⭐ |
| 网络隔离 | 限制网络访问 | iptables/network namespace | ⭐⭐⭐ |
| 进程隔离 | 限制进程创建 | cgroups/seccomp | ⭐⭐⭐⭐ |
| 资源限制 | CPU/内存/磁盘限制 | cgroups/ulimit | ⭐⭐⭐ |
| 容器化隔离 | 完全隔离的环境 | Docker/containerd | ⭐⭐⭐⭐⭐ |
OpenClaw 提供了多层沙箱保护,确保 Agent 执行安全。
// openclaw.config.ts - 沙箱配置
{
"sandbox": {
"enabled": true,
"type": "docker",
"image": "openclaw/sandbox:latest",
"resources": {
"cpu": "2",
"memory": "512MB",
"disk": "1GB"
},
"network": {
"enabled": false,
"allowedHosts": ["api.openai.com"]
},
"filesystem": {
"readonly": ["/etc", "/usr"],
"writable": ["/tmp/workspace"]
},
"timeout": "30s"
}
}
// 在沙箱中执行代码
const result = await exec({
command: 'python script.py',
sandbox: {
enabled: true,
type: 'docker',
image: 'python:3.11-slim',
network: false
}
});
最后更新:2026-06-25 | 作者:妙趣AI
有问题?联系我们