@jasonish/pi-sandbox
v0.1.2
Published
My sandbox for the shitty coding agent.
Downloads
8
Readme
@jasonish/pi-sandbox
A security-focused sandbox extension for the pi coding agent.
pi-sandbox adds runtime guardrails around tool execution with three modes:
read-only— blocksedit/writeand sandboxesbashfor read-only accessread-write— allows edits/writes only under the directory where pi was startedyolo— disables restrictions
Features
- Enforces write boundaries for
editandwrite - Wraps
bashinbubblewrap(bwrap) in non-yolomodes - Optional git metadata passthrough so worktree git operations can still work in
read-write - Session status + mode switching command/shortcut
Installation
npm install -g @jasonish/pi-sandboxOr add it where you manage your pi extensions.
Requirements
- Linux
bubblewrap(bwrap) available at:/usr/bin/bwrapor/bin/bwrap
If bwrap is missing, sandboxed bash execution is blocked unless you switch to yolo.
Usage
CLI flag
pi --sandbox-mode read-writeSupported values:
read-onlyread-write(default)yolo
Aliases accepted by the extension:
readonly,roreadwrite,rw
In-session command
/sandbox-modeor
/sandbox-mode read-only
/sandbox-mode read-write
/sandbox-mode yoloShortcut
Ctrl+Xcycles modes:read-only→read-write→yolo→ ...
Security model
read-only
editandwriteare blockedbashruns in a read-only filesystem sandboxwriteaccess via tools: none
read-write
edit/writeallowed only under the startup root directory (recursive)bashcan write to:- startup root directory
/tmp- required git metadata dirs (when applicable)
Git/worktree discovery (read-write mode)
To keep git usable in constrained environments, pi-sandbox discovers git metadata at session start:
- It checks for a
.gitentry in the startup root. - It verifies the directory is inside a work tree.
- It resolves:
git rev-parse --absolute-git-dirgit rev-parse --path-format=absolute --git-common-dir
- If either resolved directory is outside the sandbox root, it is added as an extra writable bind for sandboxed
bashinread-writemode.
Important behavior:
- This is only granted when pi starts at a worktree root (where
.gitexists 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.
yolo
- No restrictions
Notes
- Boundary checks canonicalize paths to reduce symlink/path traversal escapes.
Disclaimer
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.
License
MIT
