Configuration
Pass credentials viaspawn.env when starting a sandbox. Each call to SandboxAgent.start() can use different credentials:
spawn.env) and host config files:
| Agent | Provider | Environment variables | Config files |
|---|---|---|---|
| Claude Code | Anthropic | ANTHROPIC_API_KEY, CLAUDE_API_KEY | ~/.claude.json, ~/.claude/.credentials.json |
| Amp | Anthropic | ANTHROPIC_API_KEY, CLAUDE_API_KEY | ~/.amp/config.json |
| Codex | OpenAI | OPENAI_API_KEY, CODEX_API_KEY | ~/.codex/auth.json |
| OpenCode | Anthropic or OpenAI | ANTHROPIC_API_KEY, OPENAI_API_KEY | ~/.local/share/opencode/auth.json |
| Mock | None | - | - |
Credential strategies
LLM credentials are passed into the sandbox as environment variables. The agent and everything inside the sandbox has access to the token, so it’s important to choose the right strategy for how you provision and scope these credentials.| Strategy | Who pays | Cost attribution | Best for |
|---|---|---|---|
| Per-tenant gateway (recommended) | Your organization, billed back per tenant | Per-tenant keys with budgets | Multi-tenant SaaS, usage-based billing |
| Bring your own key | Each user (usage-based) | Per-user by default | Dev environments, internal tools |
| Shared API key | Your organization | None (single bill) | Single-tenant apps, internal platforms |
| Personal subscription | Each user (existing subscription) | Per-user by default | Local dev, internal tools where users have Claude or Codex subscriptions |
Per-tenant gateway (recommended)
Route LLM traffic through a gateway that mints per-tenant API keys, each with its own spend tracking and budget limits. Your backend issues a scoped key per tenant, then passes it to the sandbox. This is the typical pattern when using sandbox providers (E2B, Daytona, Docker).Security
Recommended for multi-tenant applications. Each tenant gets a scoped key with its own budget, so exfiltration only exposes that tenant’s allowance.Use cases
- Multi-tenant SaaS: per-tenant spend tracking and budget limits
- Production apps: exposed to end users who need isolated credentials
- Usage-based billing: each tenant pays for their own consumption
Choosing a gateway
OpenRouter provisioned keys
OpenRouter provisioned keys
Managed service, zero infrastructure. OpenRouter provides per-tenant API keys with spend tracking and budget limits via their Provisioning API. Pass the tenant key to Sandbox Agent as Easiest to set up but not open-source. See OpenRouter pricing for details.
OPENAI_API_KEY (OpenRouter uses OpenAI-compatible endpoints).LiteLLM proxy
LiteLLM proxy
Self-hosted, open-source (MIT). LiteLLM is an OpenAI-compatible proxy with hierarchical budgets (org, team, user, key), virtual keys, and spend tracking. Requires Python + PostgreSQL.Full control with no vendor lock-in. Organization-level features require an enterprise license.
Portkey gateway
Portkey gateway
Self-hosted, open-source (Apache 2.0). Portkey is a lightweight OpenAI-compatible gateway supporting 200+ providers. Single binary, no database required. Create virtual keys with per-tenant budget limits and pass them to Sandbox Agent.Lightest operational footprint of the self-hosted options. Observability and analytics require the managed platform or your own tooling.
Bring your own key
Each user provides their own API key. Users are billed directly by the LLM provider with no additional infrastructure needed. Pass the user’s key viaspawn.env:
Security
API keys are typically long-lived. The key is visible to the agent and anything running inside the sandbox, so exfiltration is possible. This is usually acceptable for developer-facing tools where the user owns the key.Use cases
- Developer tools: each user manages their own API key
- Internal platforms: users already have LLM provider accounts
- Per-user billing: no extra infrastructure needed
Shared credentials
A single organization-wide API key is used for all sessions. All token usage appears on one bill with no per-user or per-tenant cost attribution.Security
Not recommended for anything other than internal tooling. A single exfiltrated key exposes your organization’s entire LLM budget. If you need org-paid credentials for external users, use a per-tenant gateway with scoped keys instead.Use cases
- Single-tenant apps: small number of users, one bill
- Prototyping: cost attribution not needed yet
- Simplicity over security: acceptable when exfiltration risk is low
Personal subscription
If the user is signed into Claude Code or Codex on the host machine, Sandbox Agent automatically picks up their OAuth tokens. No configuration is needed.Remote sandboxes
Extract credentials locally and pass them to a remote sandbox viaspawn.env:
-e to prefix with export for shell sourcing.
Security
Personal subscriptions use OAuth tokens with a limited lifespan. These are the same credentials used when running an agent normally on the host. If a token is exfiltrated from the sandbox, the exposure window is short.Use cases
- Local development: users are already signed into Claude Code or Codex
- Internal tools: every user has their own subscription
- Prototyping: no key management needed