Agent Workspace
Agent 工作空间是 agent 执行任务的独立环境。
功能
- 文件隔离
- 环境变量隔离
- 网络隔离
- 进程隔离
工作空间结构
workspace/
├── files/ # 文件目录
├── cache/ # 缓存目录
├── temp/ # 临时文件
└── .env # 环境变量使用方法
typescript
import { workspace } from 'openclaw/concepts'
// 获取工作空间路径
const path = workspace.path()
// 读取文件
const content = await workspace.read('files/data.txt')
// 写入文件
await workspace.write('files/output.txt', 'Hello')
// 执行命令
await workspace.exec('npm install')配置
json
{
"workspace": {
"enabled": true,
"path": "~/.openclaw/workspace",
"isolation": "sandbox",
"maxSize": "1GB"
}
}隔离级别
| 级别 | 描述 |
|---|---|
none | 无隔离 |
files | 仅文件隔离 |
network | 文件和网络隔离 |
sandbox | 完整沙箱 |