My sandbox for the shitty coding agent.
npm install @jasonish/pi-sandboxA security-focused sandbox extension for the pi coding agent.
pi-sandbox adds runtime guardrails around tool execution with three modes:
- read-only — blocks edit/write and sandboxes bash for read-only access
- read-write — allows edits/writes only under the directory where pi was started
- yolo — disables restrictions
- Enforces write boundaries for edit and write
- Wraps bash in bubblewrap (bwrap) in non-yolo modes
- Optional git metadata passthrough so worktree git operations can still work in read-write
- Session status + mode switching command/shortcut
``bash`
npm install -g @jasonish/pi-sandbox
Or add it where you manage your pi extensions.
- Linux
- bubblewrap (bwrap) available at:/usr/bin/bwrap
- or/bin/bwrap
-
If bwrap is missing, sandboxed bash execution is blocked unless you switch to yolo.
`bash`
pi --sandbox-mode read-write
Supported values:
- read-onlyread-write
- (default)yolo
-
Aliases accepted by the extension:
- readonly, roreadwrite
- , rw
`text`
/sandbox-mode
or
`text`
/sandbox-mode read-only
/sandbox-mode read-write
/sandbox-mode yolo
- Ctrl+X cycles modes:read-only
- → read-write → yolo → ...
- edit and write are blockedbash
- runs in a read-only filesystem sandboxwrite
- access via tools: none
- edit/write allowed only under the startup root directory (recursive)bash
- can write to:/tmp
- startup root directory
-
- required git metadata dirs (when applicable)
To keep git usable in constrained environments, pi-sandbox discovers git metadata at session start:
1. It checks for a .git entry in the startup root.git rev-parse --absolute-git-dir
2. It verifies the directory is inside a work tree.
3. It resolves:
- git rev-parse --path-format=absolute --git-common-dir
- bash
4. If either resolved directory is outside the sandbox root, it is added as an extra writable bind for sandboxed in read-write mode.
Important behavior:
- This is only granted when pi starts at a worktree root (where .git exists in the startup root).
- If pi is started in a subdirectory of a larger repo, writes outside the startup root are intentionally not granted.
- Nested/duplicate git metadata paths are de-duplicated.
- No restrictions
- Boundary checks canonicalize paths to reduce symlink/path traversal escapes.
Use this extension at your own risk.
pi-sandbox` is primarily meant to prevent accidental writes outside your project directory. It is not a guarantee of complete isolation and is not a replacement for stronger sandboxing (for example, running inside a container or virtual machine).
If a sandbox break occurs, responsibility for validating and securing your runtime environment remains with the user/operator.
MIT