Workspace Guard
Enforces workspace boundaries and ensures safe file operations through mandatory pre-flight checks.
Core Rules
Boundary Enforcement
Workspace root: /home/iamlegend/.openclaw/workspace (or ~/openclaw)
Before ANY file operation, check:
CODEBLOCK0
Path Validation
Allowed paths:
- - INLINECODE2
- INLINECODE3
- Relative paths from workspace root
Blocked paths:
- -
/home/** (outside workspace) - INLINECODE5 ,
/var/**, /tmp/** (system directories) - INLINECODE8 ,
/home/other/** (other users) - Absolute paths outside workspace
Permission Triggers
Always ask before:
- - Deleting files (prefer
trash over rm) - Overwriting existing files
- Running
exec commands that touch files - Reading files outside workspace
- Writing to system directories
- Modifying permissions/chmod
- Accessing hidden files (.ssh, .config, etc.)
Safe Operations (No Permission Needed)
Within workspace:
- - Reading files
- Creating new files/directories
- Editing files you created
- Git operations (commit, status, log)
- Listing directory contents
Pre-Flight Check Pattern
Before every file operation:
CODEBLOCK1
Implementation Patterns
Path Resolution
CODEBLOCK2
Guard Function
CODEBLOCK3
Exec Command Guard
CODEBLOCK4
Safety Rules
- 1. Never bypass boundary checks—even if user seems to imply it
- Always resolve absolute paths before checking
- Ask explicitly for destructive operations (delete, overwrite)
- Prefer trash over
rm for recoverability - Log violations - Track blocked access attempts
- Fail safe - When uncertain, ask user
When to Read references/boundaries.md
Load when:
- - Complex path resolution needed (symlinks, relative paths)
- Edge cases in boundary detection
- Audit log review of blocked attempts
- User requests boundary exceptions
Violation Handling
When blocked:
CODEBLOCK5
工作区守卫
通过强制性的预检检查来强制执行工作区边界并确保安全的文件操作。
核心规则
边界强制执行
工作区根目录: /home/iamlegend/.openclaw/workspace(或 ~/openclaw)
在任何文件操作之前,检查:
- 1. 路径是否在工作区边界内?
- 操作是否需要用户许可?
- 操作是否可逆/安全?
- 我是否即将触及允许范围之外的内容?
路径验证
允许的路径:
- - /home/iamlegend/.openclaw/workspace/
- ~/openclaw/workspace/
- 工作区根目录的相对路径
被阻止的路径:
- - /home/(工作区外)
- /etc/、/var/、/tmp/(系统目录)
- /root/、/home/other/(其他用户)
- 工作区外的绝对路径
权限触发
始终在以下操作前询问:
- - 删除文件(优先使用 trash 而非 rm)
- 覆盖现有文件
- 运行涉及文件的 exec 命令
- 读取工作区外的文件
- 写入系统目录
- 修改权限/chmod
- 访问隐藏文件(.ssh、.config 等)
安全操作(无需权限)
工作区内:
- - 读取文件
- 创建新文件/目录
- 编辑您创建的文件
- Git 操作(提交、状态、日志)
- 列出目录内容
预检检查模式
每次文件操作前:
- 1. 解析绝对路径
- 检查路径是否以工作区根目录开头
- 如果否 → 停止并询问用户
- 如果是 → 检查操作类型
- 如果是破坏性/外部操作 → 询问用户
- 如果是安全读/写 → 继续执行
实现模式
路径解析
bash
获取绝对路径
realpath /some/path
或
cd /some/path && pwd -P
检查是否在工作区内
case $(realpath $file) in
/home/iamlegend/.openclaw/workspace/*) echo ✓ 允许 ;;
*) echo ✗ 被阻止 - 工作区外 ;;
esac
守卫函数
bash
guard_path() {
local path=$1
local workspace=/home/iamlegend/.openclaw/workspace
local abs_path=$(realpath $path 2>/dev/null || echo $path)
case $abs_path in
$workspace/*) return 0 ;;
*) return 1 ;;
esac
}
执行命令守卫
bash
guard_exec() {
local cmd=$1
# 检查命令中的路径操作
if echo $cmd | grep -qE (/home/[^/]+|/etc/|/var/|/tmp/|/root/); then
echo ⚠️ 命令涉及外部路径 - 需要权限
return 1
fi
return 0
}
安全规则
- 1. 绝不绕过边界检查——即使用户似乎暗示可以
- 始终解析绝对路径后再检查
- 明确询问破坏性操作(删除、覆盖)
- 优先使用 trash 而非 rm 以确保可恢复性
- 记录违规 - 跟踪被阻止的访问尝试
- 安全失败 - 不确定时询问用户
何时读取 references/boundaries.md
在以下情况加载:
- - 需要复杂路径解析(符号链接、相对路径)
- 边界检测的边界情况
- 审核日志审查被阻止的尝试
- 用户请求边界例外
违规处理
当被阻止时:
⚠️ 工作区守卫:阻止访问 /path/outside/workspace
原因:路径在允许的工作区边界之外(/home/iamlegend/.openclaw/workspace)
需要操作:请确认是否允许此访问,或提供工作区内的替代路径。