Keep Pi on your machine and run its tools in an E2B sandbox.
With pi --e2b, the agent works on a copy of your project in a sandbox that belongs to the Pi session. It cannot touch your files, processes or credentials. You bring its changes back with /e2b pull.
npm install -g @earendil-works/pi-coding-agent
pi install npm:@e2b/pi
export E2B_API_KEY=e2b_*** # https://e2b.dev/dashboard?tab=keyscd my-project
pi --e2b- Start. Pi opens at once. The sandbox starts with your first prompt, and your git working tree goes to it: tracked files and new files, with your uncommitted changes. Files that git ignores, such as
.env, stay on your machine. - Work.
bash,read,write,editand your!commands run in the sandbox. When the agent starts a server,preview_urlgives you a public link. - Pull.
/e2b pullshows what changed and applies it to your checkout. Or use/e2b pull --branchto get a commit on the local branchpi/<session>. Push and open the pull request with your own git. - Resume. Quit when you want.
pi --e2b -cgets the same sandbox back, with its files and running processes. A forked session (/fork,--fork) gets its own copy of the sandbox, so the two sessions do not share files.
Outside a git checkout you get an empty workspace.
| Command | |
|---|---|
/e2b |
Sandbox ID, working directory, changes not pulled yet |
/e2b pull |
Apply the sandbox's changes to your checkout |
/e2b pull --branch |
Commit them on the local branch pi/<session> instead, ready for git push (needs a clean working tree) |
/e2b kill |
Kill the sandbox |
| Flag | |
|---|---|
--e2b |
Run tools in an E2B sandbox |
--e2b-template <name> |
E2B template (default base) |
--e2b-idle <minutes> |
Idle time before the sandbox pauses (default 15) |
- Tools. Pi's tools take pluggable operations. The extension gives
bash,read,writeandeditoperations that run in the sandbox, so Pi's own tool logic stays the same.grep,findandls(off by default in Pi) would search your machine, so in E2B mode they are off and the agent searches withbash. When there is no sandbox, tools fail; they never run on your machine. - Background processes.
npm run dev &returns at once. Abort and timeout kill the whole process group. - Pause and resume. The sandbox pauses with its memory after the idle time and resumes on the next tool call or on traffic to a preview URL. On quit it pauses after one minute.
- Pull. The sandbox keeps a baseline commit of what you uploaded.
/e2b pulldiffs the sandbox files against it, whatever the agent did with git, and runsgit applyin your checkout. If your files changed in a conflicting way, nothing is applied. The baseline then moves forward, so the next pull brings only newer changes. - No credentials in the sandbox. Nothing is cloned or pushed from the sandbox, and your environment variables are not sent.
- Fork. A forked session copies the parent's sandbox with E2B's sandbox fork (files and memory, in about a second). The parent keeps its sandbox.
- Cleanup. A sandbox is killed when no Pi session refers to it any more, for example after you delete the session. This is checked on the next start, for sandboxes from the same machine and sessions in Pi's own session folder. With
--no-session, Pi offers to pull, then kills the sandbox on exit.
npm install
E2B_API_KEY=e2b_*** pi -e ./index.ts --e2b # run from source, no build step
npm run check # typecheck, oxlint (with the vendored anti-slop rules), oxfmt, offline smoke test
npm run test:live # real sandbox: tools, background processes, abort, pause and resume, upload and pullindex.ts flags, session lifecycle, /e2b command, cleanup
src/tools.ts sandbox-backed bash, read, write and edit; preview_url
src/workspace.ts upload the working tree, diff and pull changes back
MIT