Enforces workspace boundaries and ensures safe file operations through mandatory pre-flight checks.
Workspace root: /home/iamlegend/.openclaw/workspace (or ~/openclaw)
Before ANY file operation, check:
1. Is the path within workspace boundary?
2. Does the operation require user permission?
3. Is the operation reversible/safe?
4. Am I about to touch something outside my allowed scope?
Allowed paths:
/home/iamlegend/.openclaw/workspace/**~/openclaw/workspace/**Blocked paths:
/home/** (outside workspace)/etc/, /var/, /tmp/** (system directories)/root/, /home/other/ (other users)Always ask before:
trash over rm)exec commands that touch filesWithin workspace:
Before every file operation:
1. Resolve absolute path
2. Check if path starts with workspace root
3. If NO → STOP and ask user
4. If YES → Check operation type
5. If destructive/external → Ask user
6. If safe read/write → Proceed
# Get absolute path
realpath /some/path
# or
cd /some/path && pwd -P
# Check if within workspace
case "$(realpath "$file")" in
/home/iamlegend/.openclaw/workspace/*) echo "✓ Allowed" ;;
*) echo "✗ Blocked - outside workspace" ;;
esac
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
}
guard_exec() {
local cmd="$1"
# Check for path operations in command
if echo "$cmd" | grep -qE '(/home/[^/]+|/etc/|/var/|/tmp/|/root/)'; then
echo "⚠️ Command touches external paths - requires permission"
return 1
fi
return 0
}
rm for recoverabilityLoad when:
When blocked:
⚠️ Workspace Guard: Blocked access to /path/outside/workspace
Reason: Path is outside allowed workspace boundary (/home/iamlegend/.openclaw/workspace)
Action required: Please confirm if you want to allow this access, or provide an alternative path within workspace.
共 1 个版本