workspace-isolation/
When you run multiple OpenHands conversations in parallel on a local machine, each agent works in a different directory. Without isolation, agents can accidentally cd into a sibling project, delete the wrong files, or write test output that collides with another agent’s work.
This example enforces directory boundaries with PreToolUse hooks on both the terminal and file_editor tools.
In OpenHands Cloud, each conversation gets its own container — workspace isolation is already guaranteed. This example is primarily useful for local setups running multiple conversations in parallel.
What Gets Blocked
Terminal Commands
File Editor Operations
The # read-only Escape Hatch
Add # read-only to a command to allow reading system files outside the workspace:
How the Hooks Work
Two hooks in thesandbox-enforcer plugin work together:
Terminal hook — extracts the command name and target path, checks whether the path is inside the workspace:
view, blocks write commands that target paths outside the workspace.
Both hooks use OPENHANDS_PROJECT_DIR (set by OpenHands Cloud/Enterprise) or fall back to $PWD.
Try It
- Via API
- Via Badge
Local Multi-Agent Setup
Limitations
This is a heuristic-based implementation. For production multi-tenant use, see jpshackelford/lxa, which uses Python with fullpathlib path resolution, symlink following, and shlex parsing.
Why Inline Shell
Hook scripts in plugins run with the working directory set to the agent’s workspace — there’s no plugin-root path variable. External script files (hooks/scripts/check.sh) won’t resolve at runtime. The hooks inline the POSIX-sh logic directly as a command string in hooks.json. Reference copies of the same scripts in hooks/scripts/ exist for readability.
See Also
- Command Blacklist — Block specific dangerous commands
- Command Whitelist — Allow only approved commands
- Hooks — Full hooks documentation

