Secret removes that trade-off.
Prerequisites
- The
boxlitePython package and a machine with hardware virtualization — see Installation. - An API key for a provider Pi supports (Anthropic, OpenAI, Google, or any endpoint speaking one of those APIs).
- A Node image for the box. Pi installs from npm, so
node:20-slimor newer works.
Quick Example
Install Pi into a box, point it at a provider, and run one non-interactive prompt.disk_size_gb=8 has ample headroom.
Parameters and Returns
The CLI surface used above, all frompi --help:
Pi reads its configuration from
~/.pi/agent. Set PI_CODING_AGENT_DIR to relocate it — inside a box that keeps configuration on a path you control rather than in the image’s home directory.
Machine-readable output
--mode json emits one JSON object per line. The type sequence for a successful turn is:
message_end carries what you need:
stopReason, not the exit code. pi -p exits 0 even when the model call fails; the failure shows up as stopReason: "error" plus an errorMessage field, and Pi retries up to three times (auto_retry_start, backing off 2000 ms then 4000 ms) before giving up — still with exit code 0.
Keeping the provider key out of the box
The example above passes the key in as an environment variable, which means it exists inside the sandbox. When that is not acceptable, inject it at the proxy instead: the box sees only a placeholder, and BoxLite substitutes the real value on outbound requests to the hosts you allow.Custom or self-hosted endpoints
Pi’s built-in providers use their vendors’ own endpoints and ignoreANTHROPIC_BASE_URL / OPENAI_BASE_URL. Pointing --provider anthropic at a compatible third-party endpoint through those variables fails with a 401 authentication_error from the official host.
To use a different endpoint, declare a provider in models.json under the directory PI_CODING_AGENT_DIR points at:
--provider my-endpoint --model my-endpoint/<MODEL_ID>. Confirm the box can see it with pi --list-models before spending a real prompt.
Troubleshooting
Related
- Run Claude Code — the same pattern with the Claude Code CLI, plus
SkillBoxand a noVNC desktop. - Run Codex — OpenAI’s CLI, which reads its endpoint from environment variables instead.
- Secrets and hardening — keeping the provider key outside the sandbox.
- Drive a sandbox from your agent loop — the inverse arrangement, where your process owns the loop.

