PANGEA / EPHEMERAL SESSIONS
Run one isolated sandbox per conversation.
Any deployed Dockerfile HTTP app (dockerfile-http-v1) can spin up on-demand, kernel-isolated gVisor containers per user session—checking out pre-warmed pods in roughly 0.1s via SandboxWarmPool or cold-starting with per-session env and read-only reference files—and automatically destroy them when idle or expired.
Use Ephemeral Agent Sessions when a web app or service needs a stateful AI worker (for example a CLI agent or document reviewer holding multi-turn context in memory or /tmp) isolated per conversation rather than shared inside one long-lived web replica. Inspect active pools and live sessions read-only from the Ephemeral agent sessions panel in Your apps.
1. Deploy an HTTP agent app (dockerfile-http-v1)
Build a container that serves an HTTP server on $PORT (default 8080). Every ephemeral session launches from your project’s latest verified production image. Keep two routing rules in mind:
- Expose app endpoints outside
/healthz: requests tohttps://sandbox.pangea.host/healthzcheck router health directly, so serve agent routes on paths such as/,/chat,/history, or/ready. - Shared AI ready: if you enable Shared AI (LLM & Speech) on the app (or pass LLM keys via allowed app secrets), each session container receives the configured model and CA variables cleanly.
2. Configure the session pool
Configure concurrency, per-session compute, lifetimes, and optional warm standby replicas via CLI (requires pangea-cli 0.1.61a19 or later for pangea sessions) or MCP:
pangea sessions pool set -p PROJECT_ID \
--warm-replicas 1 \
--max-concurrent 4 \
--cpu-m 500 \
--memory-mib 1024 \
--scratch-mib 512 \
--idle-ttl 900 \
--max-ttl 7200- WarmPool mode (
warm_replicas > 0): keeps clean standby sandboxes booted and ready. Calling create with no per-sessionenv/filesor resource overrides claims a standby pod immediately (~0.1s). - Secret isolation (default off): project secrets are not injected into session pods by default. Add
--inherit-secrets --allowed-secret-keys KEY1 KEY2only when specific keys are needed. - Manage or disable: inspect state with
pangea sessions pool get -p PROJECT_IDor turn off warm standbys and new sessions withpangea sessions pool delete -p PROJECT_ID.
3. Issue a least-privilege session token (pga_ses_...)
Mint a project-scoped token dedicated to session lifecycle operations—give this token to your calling web backend instead of a workspace deploy credential:
pangea sessions token create -p PROJECT_ID --label my-web-app --ttl-days 30A pga_ses_ token holds only the sessions scope for that single project: it can create, list, inspect, extend (touch), pause, resume, and delete sessions on PROJECT_ID, and cannot deploy code, read encrypted app secrets, modify session pool limits, or access other workspaces. Manage issued tokens anytime with pangea sessions token list or pangea sessions token revoke TOKEN_ID.
4. Launch, talk over sandbox.pangea.host, extend, and clean up
Call the Agent Bridge endpoint https://pangea.host/api/agent/v1/projects/PROJECT_ID/sessions?wait=true with Authorization: Bearer pga_ses_... (or pass an empty JSON body for sub-second WarmPool checkout, or per-session env / files for an isolated cold start in ~5s):
{
"env": {
"CUSTOMER_TIER": "pro",
"TOPIC": "onboarding"
},
"files": {
"context/policy.md": "# Internal FAQ\nAnswer using this policy."
},
"idle_ttl_seconds": 900,
"max_ttl_seconds": 7200
}When files are provided on creation, Pangea stores them in an ephemeral Kubernetes Secret with ownerReferences tied to the Sandbox and mounts them read-only at /run/pangea-session/files/<rel_path>. When the session becomes ready, use the returned url and signed Ed25519 Scoped-Token v2 headers directly for multi-turn HTTP, Server-Sent Events (SSE), or WebSocket requests:
curl -fsS https://sandbox.pangea.host/chat \
-H "Authorization: <session.headers.Authorization>" \
-H "X-Sandbox-ID: <session.headers.X-Sandbox-ID>" \
-H "X-Sandbox-Namespace: <session.headers.X-Sandbox-Namespace>" \
-H "X-Sandbox-Port: <session.headers.X-Sandbox-Port>" \
-H "Content-Type: application/json" \
-d '{"message":"Summarize policy.md"}'- Extend active conversations: call
POST /api/agent/v1/projects/PROJECT_ID/sessions/SESSION_ID/touch(orpangea sessions touch) to push outexpires_atup tomax_expires_at. - Pause & resume across minutes to days (
exec_mode: "builtin"): callPOST /api/agent/v1/projects/PROJECT_ID/sessions/SESSION_ID/pause?wait=true(orpangea sessions pause) with optionalpaths(up to 16 relative or/tmp/...paths such asworkspaceor.claude) andttl_days(1–30). Pangea archives those directories, tears down the running Pod so its CPU, memory, andmax_concurrentslot are freed immediately while paused, and restores them onto aSandboxWarmPoolor fresh Pod with fresh routing headers when you callPOST /api/agent/v1/projects/PROJECT_ID/sessions/SESSION_ID/resume?wait=true(orpangea sessions resume, with optionalidle_ttl_seconds/max_ttl_seconds). Both endpoints accept workspace CLI tokens andpga_ses_session tokens. - Immediate or automatic teardown: call
DELETE /api/agent/v1/projects/PROJECT_ID/sessions/SESSION_IDwhen the user finishes, or let the reconciler delete the Sandbox and Secret automatically once idle/max TTL expires.
5. MCP tools & AI agent prompt
Your coding assistant can manage session pools, test sandboxes, and issue app tokens via MCP tools:
pangea_get_session_pool·pangea_set_session_poolpangea_create_session·pangea_list_sessions·pangea_delete_sessionpangea_create_session_token
Configure Ephemeral Agent Sessions on Pangea project PROJECT_ID viapangea_set_session_pool(warm standby replicas for instant checkout or cold start for per-session context), create apga_ses_token withpangea_create_session_token, and integratePOST https://pangea.host/api/agent/v1/projects/PROJECT_ID/sessions?wait=trueplushttps://sandbox.pangea.hostrouting (remembering not to expose app routes at/healthz).
Custom Dockerfile & Session-only projects (session_only: true)
If your image only exists to power on-demand sandboxes (for example a coding tool image with git, python3, bun, claude, or codex) and does not serve a public website, create the project with session_only: true (or pangea create --dockerfile-http-v1 --session-only). Session-only projects skip public Ingress and web serving while keeping builds, secrets, and ephemeral pools intact:
- No HTTP server required in your Dockerfile: pair
session_only: truewithexec_mode: "builtin"so you do not need to write or maintain a custom HTTP server inside the container. - Writable
/tmpunder read-only root: session pods run withreadOnlyRootFilesystem: true, so setENV HOME=/tmpin your Dockerfile and keep scratch files or checkouts inside/tmp. - Stateless-only scope:
session_only: truerejects incompatible web features includingpersistent_data: true,autoscaling,processes,redis,litestream, andidle_sleep: true.
Built-in Exec API (exec_mode: "builtin")
Enable exec_mode: "builtin" on session-pool (via pangea sessions pool set --exec-mode builtin or PUT /v1/projects/PROJECT_ID/session-pool) to run commands inside any active sandbox over https://sandbox.pangea.host with your session’s scoped headers:
- One-shot or streaming NDJSON (
POST /_pangea/exec): send{"cmd":["git","status"],"cwd":"/tmp"}tohttps://sandbox.pangea.host/_pangea/execwithAuthorization: <session.headers.Authorization>and sandbox routing headers to execute a command and stream structured stdout/stderr/exit output. - Bidirectional WebSocket (
wss://sandbox.pangea.host/_pangea/exec/ws): connect over WebSocket, send{"type":"spawn","cmd":[...],"cwd":"/tmp","env":{...}}, streamstdin/stdin_eofandsignalframes, and receive livestdout,stderr, andexitevents—ready for TypeScript / BunspawnClaudeCodeProcessadapters in the Claude Agent SDK (see thenode:26-slimreference sandboxes inexamples/coding-agent-sandbox/andexamples/claude-agent-sandbox/).
Outbound Credential-Injecting Proxy (egress_proxies)
Keep raw API keys such as ANTHROPIC_API_KEY or OPENAI_API_KEY outside the sandbox container. Instead of setting inherit_secrets: true, register up to 8 outbound proxy routes in egress_proxies on session-pool:
{
"exec_mode": "builtin",
"egress_proxies": {
"anthropic": {
"upstream": "https://api.anthropic.com",
"secret_key": "ANTHROPIC_API_KEY",
"header": "x-api-key",
"env_url": "ANTHROPIC_BASE_URL",
"env_token": "ANTHROPIC_API_KEY"
}
}
}Each session container receives only an ephemeral pga_pxy_ proxy token in env_token and the proxy base URL in env_url (for example ANTHROPIC_BASE_URL or OPENAI_BASE_URL). The pangea-egress-proxy authenticates the pga_pxy_ token and injects the real project secret into the configured outbound header solely for requests forwarded to the matching https:// upstream—with a 600s streaming read timeout for long-running LLM responses—so untrusted code inside the sandbox never sees the raw key.
Security boundaries & limits
- Isolation: every session pod runs in the gVisor runtime class with non-root UID 1000, dropped capabilities, read-only root filesystem (writable
/tmpscratch), and Cilium network policies that allow public HTTPS egress while blocking cluster metadata and cross-tenant/cross-session east-west traffic. - No persistent
/datavolume: sessions do not mount a persistent/datavolume; return durable outputs via your calling web backend or usepause/resumeto archive selected/tmpdirectories between turns. - Capacity accounting & snapshots: paused sessions preserve selected
/tmpdirectories in snapshot object storage for 1–30 days without holding Pod compute ormax_concurrentslots; active session reservations appear undersession_reservedandtotal_reservedinpangea usage, and403 LIMIT_EXCEEDEDreturns an exact workspace CPU/memory breakdown when shared runtime capacity is full. - Bounds per project: up to 16 warm standby replicas, 32 concurrent sessions, CPU 50–8000m, memory 64–16,384 MiB,
/tmpscratch 128–32,768 MiB, idle/max TTL 60–86,400 seconds, up to 32 session env vars (4 KiB each), up to 32 UTF-8 files (512 KiB total), and up to 20 activepga_ses_tokens (90-day max lifetime).
Configure Shared AI · Overview on Features · Back to the app guide