059. Cages reach their models through the agent, and hold no keys

Status: accepted 2026-10-16, built the same day: - Phase 1: sealed cages running Claude Code reach Anthropic through the gateway, and hold no token. - Phase 2: caged pi sessions reach their cloud providers through it, and hold no model keys.

The difference between caged and sealed is the network: a sealed cage gets the internet and nothing local. Neither may leak the owner's credentials, and since phase 3 neither holds them.

Context

A caged session needs a model, and today it gets the credential for one: every *_API_KEY and *_TOKEN variable of the agent's is passed into a caged session, and a sealed cage runs on the machine's sealed Claude token (ADR-045). The code in a sealed cage is code nobody vouches for, and a caged session can be talked into anything. Either can read the key and send it anywhere it can reach, which for a sealed cage is the internet.

The Lambda Prize harness (lprize-env) split this in two: a LiteLLM proxy held the real key, and the sandbox talked to the proxy with a throwaway token. That worked, at the price of another container per sandbox.

The harnesses come and go (Claude Code, pi; opencode and codex are candidates), so whatever this is has to be pluggable, not written per harness in the cage code.

Decision

The agent is the gateway. Every cage already has a socket to its own agent (ADR-044). The agent serves model upstreams on it at /llm/<upstream>/… and forwards each request to the upstream's real base URL, dropping the caller's credentials and adding the real ones. Only the model endpoints are forwarded, and nothing else of the upstream's API.

Upstreams are named, with their credentials kept by the agent: anthropic (an API key, or the machine's Claude token for sealed cages), openrouter, venice, openai, and local ones such as k11, which need none. Adding one is a name, a base URL and where its key is read from.

Inside the cage, a forwarder with no secret. Harnesses want an http:// base URL, not a socket. shrooms-agent llm-forward is the agent's own binary, already mounted read-only in the cage. It listens on the cage's loopback and passes each request to the socket. It holds nothing worth stealing.

Harnesses plug in by saying how they are pointed elsewhere. A harness that can use the gateway implements one more method. Given the gateway's base URL for each upstream, it returns the environment and the files its process needs:

Then no keys go into the cage, and nothing else unasked for. A caged session gets, of the agent's own environment, only what is named: the time zone, the locale, the proxies, and the settings its harness asks for (CageEnv, e.g. Claude Code's model choices). Everything else stays out, whatever it is called, including what is added to the agent later. A filter of key-like names was tried first and missed VENICE_INFERENCE_KEY on proteus (2026-10-16). Sealed cages never passed any.

Consequences