Skip to main content
Pi is a coding-agent CLI with read, bash, edit, and write tools. Its own documentation notes that running the whole process in a plain container means “provider API keys enter the container” — a box plus Secret removes that trade-off.

Prerequisites

  • The boxlite Python 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-slim or newer works.

Quick Example

Install Pi into a box, point it at a provider, and run one non-interactive prompt.
Verified inside a box on macOS (Apple Silicon): the box was up in 19 s, the global npm install finished at 72 s, and the prompt returned at 77 s. An 8 GB disk came back 7% used, so disk_size_gb=8 has ample headroom.

Parameters and Returns

The CLI surface used above, all from pi --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:
The assistant’s message_end carries what you need:
Read 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.
Substitution covers request headers, the URL query string, and the request body — not the URL path. Details and the exact placeholder format are on Secrets and hardening.

Custom or self-hosted endpoints

Pi’s built-in providers use their vendors’ own endpoints and ignore ANTHROPIC_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:
Then select it with --provider my-endpoint --model my-endpoint/<MODEL_ID>. Confirm the box can see it with pi --list-models before spending a real prompt.

Troubleshooting