Secrets and the egress gateway
After this page you will know how a boxed agent reaches the network at all, and how it can use a key it never holds. The story needs it now: Claude Code starts in the box but says “Not logged in”, and the security engineer does not want the real model key or the Cloudflare tokens inside the agent’s process, where a prompt injection or a log line could carry them away.
Your files at this point
packs = ["@box/base"]
[project]access = "read"
[storage]directories = ["config", "tmp"]
[agent]command = ["${{ home }}/.local/bin/claude", { slot = "agent-args" }]
[agent.env]CLAUDE_CONFIG_DIR = "${{ storage.config }}"CLAUDE_CODE_TMPDIR = "${{ storage.tmp }}"{ "mcpServers": { "cloudflare": { "type": "http", "url": "https://mcp.cloudflare.com/mcp", "headers": { "Authorization": "Bearer ${CLOUDFLARE_MCP_TOKEN}" } } }}Text description of the diagram
Stage 2 of 5.
Pieces in the picture:
- the macOS keychain, which holds the three secrets; the developer reads them into shell variables
- the developer's terminal
- Claude Code, the agent
- the contained filesystem view: only the paths the profile grants exist for the agent (new at this stage)
- the box CLI and Box Core, which build the box and run its trusted process (new at this stage)
- stand-in secrets: the agent gets placeholders, the real values stay in the trusted process (new at this stage)
- the egress gateway, which every network request from the box goes through (new at this stage)
- the Anthropic API
- Cloudflare's MCP server
- the Cloudflare API
- the sample app: the Worker box-poc-workshop with its D1 database, KV namespace and Workers Logs; the logs and the database hold attendee names and email addresses
- Boundaries: the box, agent's sandbox, trusted process.
Nothing new is added to the picture on this page. It is about two pieces already in it: the egress gateway, which every network request from the box goes through, and the stand-in secrets, which the agent holds in place of the real values.
Two ideas before the first run
Section titled “Two ideas before the first run”The egress gateway. The agent’s sandbox has no direct network access. Box sets proxy variables for the agent (HTTPS_PROXY, HTTP_PROXY, NODE_USE_ENV_PROXY=1), so its traffic goes to the egress gateway inside the trusted process. The gateway opens every connection itself. It decrypts HTTPS with a certificate authority Box makes for this box (given to the agent as SSL_CERT_FILE and NODE_EXTRA_CA_CERTS), so it can read each request. For each new connection it asks the policy engine to decide a net:connect, and for each request an http:request. It has no allow-list of its own: what the policy does not permit is refused. That is default deny.
Stand-in secrets. Box can bind a credential to a set of hosts. The real value stays in the trusted process. The agent gets a stand-in (Box’s design notes call it a phantom): a random value of the same shape, in the same variable. When the agent sends a permitted request to a bound host, the gateway replaces the stand-in with the real value on the way out. The agent can use the key. It cannot read it, print it or send it anywhere else.
These are from the Box design pages (docs/design/architecture.md, docs/design/credentials.md); the variable names were measured in this workshop’s research by running /usr/bin/env as the boxed agent.
The run. The free check from the previous page, with the profile as it stands.
What this doesStarts Claude Code in the box for one headless turn, with an invalid model key so nothing is billed.
ANTHROPIC_API_KEY=sk-ant-preflight-invalid-key box run ws --no-banner -- --bare -p "Say hello." \ --max-turns 1 --model claude-sonnet-5-5 < /dev/nullANTHROPIC_API_KEY=sk-ant-preflight-invalid-keyrun ws --no-banner --ws without the activity banner; everything after -- goes to Claude Code.--bareANTHROPIC_API_KEY.-p "Say hello."--max-turns 1--model claude-sonnet-5-5< /dev/nullThe flags are explained in full on the previous page.
What we see. The same as at the end of the last page:
Not logged in · Please run /loginClaude Code does not say why. Box can: every decision the box made is in the run’s history. First find the run.
What this doesLists the runs of profile ws, newest first.
box runs list wsruns listPROFILE UPDATED (UTC) BOX ID, newest first. Finished runs and running ones are both listed.wsThe newest box ID is also in the box: policy history: box runs history b-... line that box run printed before the agent started.
What this doesPrints every policy decision the box made in that run.
box runs history <the newest BOX ID>runs history<the newest BOX ID>b-e4d0f0dc5f9bfc35. Type it without the angle brackets.What we see (the CLI separates the columns with tabs):
TIME (UTC) RESULT ACTION RESOURCE RULE REASON2026-11-22T08:28:58.260432000Z installed policy policy.dw - -2026-11-22T08:28:58.712931000Z deny net:connect api.anthropic.com:443 <default-deny> no permit matchedTwo lessons in two rows:
- The
ANTHROPIC_API_KEYyou exported in set-up did not reach the agent. The agent inherits nothing from your shell, so Claude Code had no key at all, and said “Not logged in”. - Even with a key, Claude Code could not reach the model. The gateway refused the connection to
api.anthropic.comon port 443, because no rule permits it.<default-deny>in the RULE column means exactly that.
The first row, installed policy, is the run’s policy.dw being loaded. Box writes one even though the profile names no policy file: it holds the rules Box generates from the profile (Part 3 looks inside).
Read morebox runs list and box runs historyBox docs
Read moreArchitecture: the egress gatewayBox docs
What we add. A credentialed route for the Anthropic API.
packs = ["@box/base"]
[project]access = "read"
[storage]directories = ["config", "tmp"]
[agent]command = ["${{ home }}/.local/bin/claude", { slot = "agent-args" }]
[agent.env]CLAUDE_CONFIG_DIR = "${{ storage.config }}"CLAUDE_CODE_TMPDIR = "${{ storage.tmp }}"
[egress.anthropic]destinations = ["api.anthropic.com"]secret.ref = "env://ANTHROPIC_API_KEY"secret.header = "x-api-key"secret.phantom_prefix = "sk-ant-"Each line, in order:
[egress.anthropic]declares a route: hosts the box may reach.anthropicis the route’s name; Box uses it in the names of the rules it writes.destinations = ["api.anthropic.com"]is the host. Box writes two permits for it:route_anthropic_connect(net:connectto the host on port 443) androute_anthropic_request(everyhttp:requestto the host).secret.ref = "env://ANTHROPIC_API_KEY"names where the real value comes from: the variableANTHROPIC_API_KEYin the shell that runsbox run. Box reads it once, at start. The agent then finds a stand-in in its ownANTHROPIC_API_KEY.secret.header = "x-api-key"is the header the gateway writes the real key into. Anthropic’s API reads its key fromx-api-key. The default isAuthorization.secret.phantom_prefix = "sk-ant-"makes the stand-in start like an Anthropic key:sk-ant-plus 64 random hex characters, so Claude Code accepts it as one. Without the line the stand-in starts with Box’s default prefix,strands_box_; whether Claude Code would accept that was not checked.
The run. The same free check.
What we see. Claude Code now prints:
Invalid API key · Fix external API keyThat is progress. The request reached Anthropic with the swapped key, and Anthropic refused it, because the key in your shell for this command is the invalid one. The history shows the path (time column left out):
installed policy policy.dw -permit net:connect api.anthropic.com:443 route_anthropic_connectpermit http:request api.anthropic.com:443/api/claude_code/settings route_anthropic_requestpermit http:request api.anthropic.com:443/api/claude_code/policy_limits route_anthropic_requestpermit http:request api.anthropic.com:443/api/eval/sdk-<id> route_anthropic_requestpermit http:request api.anthropic.com:443/v1/messages route_anthropic_requestpermit http:request api.anthropic.com:443/api/claude_code/organizations/metrics_enabled route_anthropic_requestpermit http:request api.anthropic.com:443/api/event_logging/v2/batch route_anthropic_requestdeny net:connect http-intake.logs.us5.datadoghq.com:443 <default-deny>There are more net:connect rows than shown. /v1/messages is the model call. With the real key in your shell (the same command without the prefix), Claude Code answers the prompt.
One limit to know. The gateway cannot tell which process in the box sent a request, so every process in a box can use every credential route (docs/user/egress.md). A route protects the key’s value, not who may use it.
Read moreEgress and credentialsBox docs
Read moreCredentials: how stand-ins workBox docs
Read moreThe @box/anthropic packBox docs
The run. The same profile, with ANTHROPIC_API_KEY removed for one command.
What this doesRuns the box with ANTHROPIC_API_KEY removed from the environment, to see what Box does without the real value.
env -u ANTHROPIC_API_KEY box run ws --no-banner -- --versionenv -u ANTHROPIC_API_KEYenv runs the rest of the line with a changed environment; -u removes one variable. Your shell keeps it.-- --versionWhat we see (exit 1):
strands-box: error: credential setup failed: credential variable ANTHROPIC_API_KEY is not set, or holds only whitespaceBox stops before the agent starts. It does not hand the agent an empty stand-in and hope. Box printed a box ID before this error; in the check for this page, box runs list afterwards showed no saved run for the profile.
The history in iteration 2 shows more than the task needs: Claude Code’s usage reporting (event_logging, metrics_enabled) and a refused Datadog host.
What we add. Two of Claude Code’s own variables.
packs = ["@box/base"]
[project]access = "read"
[storage]directories = ["config", "tmp"]
[agent]command = ["${{ home }}/.local/bin/claude", { slot = "agent-args" }]
[agent.env]CLAUDE_CONFIG_DIR = "${{ storage.config }}"CLAUDE_CODE_TMPDIR = "${{ storage.tmp }}"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1"DISABLE_AUTOUPDATER = "1"
[egress.anthropic]destinations = ["api.anthropic.com"]secret.ref = "env://ANTHROPIC_API_KEY"secret.header = "x-api-key"secret.phantom_prefix = "sk-ant-"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1"turns off Claude Code’s non-essential network traffic, such as usage reporting.DISABLE_AUTOUPDATER = "1"stops Claude Code from trying to update itself from inside the box.
The run. The same free check. What we see: the history now holds only the settings, policy_limits and /v1/messages requests to api.anthropic.com, and no Datadog row.
Read moreClaude Code settings and environment variablesClaude Code docs
“Detected a custom API key”: the question Claude Code asks
Section titled ““Detected a custom API key”: the question Claude Code asks”Every check on this page is headless. When you run Claude Code in the box interactively (act b1 does), it asks a question on its first screen:
Detected a custom API key in your environment
ANTHROPIC_API_KEY: sk-ant-...1031a80502699ab53f77
Do you want to use this API key? Yes❯ No (recommended)- Why it asks. Claude Code found
ANTHROPIC_API_KEYin its environment, and asks before it uses a key it did not set up itself. - What it shows. The last 20 characters of the key. In the box these are the end of Box’s stand-in, not of your key. The example above is from a real check; your characters will differ.
- What to answer. Press the Up arrow, then Enter, to choose Yes. The default, No, sends Claude Code to its login flow, which cannot work here.
- Why it asks every run. Claude Code remembers its answers in its configuration folder, which is in the box’s storage, so the theme, the notes and the folder-trust question are asked once. But the stand-in is new on every run, so to Claude Code it is a new key each time (a gap, listed in Builds and gaps).
Compare act a, without a box: there the 20 characters are the end of your real key. Do not show that screen on a projector.
The same move for the Cloudflare tokens
Section titled “The same move for the Cloudflare tokens”The model key is one of the three secrets from set-up. The two Cloudflare tokens get the same treatment, in two places later on:
| Secret | Who uses it | Where it is declared | Page |
|---|---|---|---|
CLOUDFLARE_MCP_TOKEN |
Claude Code, to talk to Cloudflare’s MCP server | in the [mcp.cloudflare] table, with the same secret.ref = "env://..." line |
MCP through the broker |
CLOUDFLARE_API_TOKEN |
the scripts of the local exec proxy, calling the Cloudflare API directly | in a route [egress.cloudflare-api] |
Network rules for each API request |
Why the MCP token does not get a plain route here: a route would only open the host. The [mcp.cloudflare] table also makes Box recognise the traffic as MCP and decide each tool call, which is the next page. Without a phantom_prefix, a Cloudflare stand-in starts with Box’s default prefix: strands_box_ plus 64 hex characters (measured in this workshop’s research).
Both Cloudflare tokens are deliberately broad: they can read the leaderboard app’s logs and delete its Worker. So when something is refused later, the refusal is Box’s, not Cloudflare’s.
The two seats
Section titled “The two seats”The real model key is out of the agent’s reach, and bound to one host. Every connection the agent makes is now a decision you can read with box runs history, including the ones nothing permits. What a route does not give you: any say over which paths on the host are used. The route admits all of api.anthropic.com.
Claude Code reaches its model, with the key you already have in your shell. Nothing about how you talk to it changes, except one extra Yes on the key question in interactive runs. The two variables in iteration 4 cost nothing.
What to remember
Section titled “What to remember”- The agent has no network of its own. Every request goes through the egress gateway, which asks the policy engine about each connection and each request. Nothing permitted means refused.
- A route (
[egress.<name>]) opens hosts. Withsecret.*it also binds a credential: the agent holds a stand-in, the gateway swaps in the real value for those hosts only. box runs list <profile>finds a run;box runs history <box ID>shows what Box decided in it, and which rule decided.- A missing secret variable stops the run before the agent starts.
Read moreEgress and credentialsBox docs
Read moreCredentials designBox docs
Read moreWhat Box protects, and its limitsBox docs