Skip to content
Agent in a Box: sandboxing AI coding agents with Strands Box

Network rules for each API request

After this page you will know how a Box rule names one HTTP request, by its method, host and path, and you will have written the rules that let the agent read the Worker list and the deployments of the workshop app while refusing its logs. The story needs this now because the local exec proxy sends real API requests through Box’s egress gateway, and so far the gateway refuses every one of them.

Your files at this point

The files as they stand at the end of the local exec proxy. The three .dw files of Parts 3 and 4 may still be in the profile folder; no profile lists them, so they do nothing.

$HOME/box-ws/profiles/ws/profile.toml
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-"
[mcp.exec-proxy]
type = "stdio"
command = ["${{ home }}/.local/share/mise/installs/node/22.23.4/bin/node", "${{ home }}/box-exec-proxy/proxy/exec-proxy"]
filesystem.read = [
"${{ home }}/.local/share/mise/installs/node/22.23.4",
"${{ home }}/box-exec-proxy/proxy",
"${{ home }}/box-exec-proxy/spec",
]
env = { CLOUDFLARE_ACCOUNT_ID = "0123456789abcdef0123456789abcdef" }
$HOME/leaderboard-ops/exec-proxy.json
{
"mcpServers": {
"exec-proxy": {
"command": "node",
"args": ["${HOME}/box-exec-proxy/proxy/exec-proxy"]
}
}
}
Architecture, stage 5 of 5Pieces: macOS keychain, Developer's terminal, Claude Code, Contained filesystem view, Local exec proxy, box CLI and Box Core, Stand-in secrets, Egress gateway, MCP broker, Tool catalog, Policy engine, Records, Anthropic API, Cloudflare MCP server, Cloudflare API, Sample app. New at this stage: Local exec proxy. A full text description follows the diagram.The boxAgent's sandboxMCP server's sandboxTrusted processbox runstartsstdiomacOS keychainthree secretsDeveloper'sterminalClaude Codethe agentContainedfilesystem viewLocal exec proxysearch and executenewbox CLI and Box CoreStand-in secretsreal values stay hereEgress gatewaydecides net:connect,http:request, andmcp:call for aremote MCP serverMCP brokerlocal MCP serversTool catalogstaged, typed per toolPolicy engineCedar and Dogwood policy files (.dw)Recordsrecords.jsonl and the run's historyAnthropic APIapi.anthropic.comCloudflare MCP serverper-endpoint mode;not on act c's pathCloudflare APIapi.cloudflare.comSample appWorker box-poc-workshop,its D1, KV andWorkers Logsholds names and email addressesnew at this stage
Text description of the diagram

Stage 5 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
  • the local exec proxy, an MCP server with search and execute tools, in its own sandbox inside the box (new at this stage)
  • the box CLI and Box Core, which build the box and run its trusted process
  • stand-in secrets: the agent gets placeholders, the real values stay in the trusted process
  • the egress gateway, which every network request from the box goes through
  • the MCP broker, which starts local MCP servers and decides their calls
  • the staged tool catalog: Box types each tool from the server's tools/list before the agent may call it
  • the policy engine, which reads the Cedar and Dogwood policy files
  • the records: every decision, written where the agent cannot reach
  • the Anthropic API
  • Cloudflare's MCP server (not on act c's path)
  • 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, mcp server's sandbox, trusted process.

The picture has not changed since the last page. What changes here is what the egress gateway decides: until now it decided the traffic of Claude Code and of the vendor’s MCP server; from this page on it also decides every request the exec proxy sends to api.cloudflare.com.

In Parts 3 and 4 the security engineer’s rules decided a tool call. Here they decide the API request itself. Both are Cedar rules in a .dw file; what differs is the action they name and the fields they can read.

Parts 3 and 4: a tool call Part 5: an API request
Action Box::Action::"mcp:call", or a tool’s own action such as cloudflare::Action::"execute" Box::Action::"net:connect" and Box::Action::"http:request"
Raised by the gateway, for a remote MCP server the gateway, for any connection out of the box
Fields the rule reads server, method, tool, and the tool’s typed arguments host, port, method, path, body_bytes, intercepted
What it knows about the effect what the tool’s name and arguments promise the exact request that would reach Cloudflare

The difference matters for the story. In act b2 a rule on execute could only refuse the whole tool, because the script was out of sight. In act b3 a rule on a tool name relied on the model picking the tool on the list. A rule on the request does not care which tool or which script sent it.

The egress gateway decides each request twice (Box docs, policy/actions.md):

  • net:connect, once per connection, before TLS. It knows the host and the port. A refusal here closes the connection before anything is sent.
  • http:request, once per request inside the connection, after the gateway has decrypted it. It knows:
    • method: GET, POST and so on.
    • path: the URL path in canonical form, without the query string. The gateway decodes harmless percent escapes and removes . and .. segments, but it keeps // and %2F as they are.
    • body_bytes: the length of the body. The body itself is not visible to policy.
    • intercepted: true when the gateway decrypted the TLS exchange, so method and path are what was really sent.

A route in the profile, an [egress.<name>] table, writes both permits for its hosts: one for net:connect and one for http:request, for every method and every path. That is what you add in iteration 2, and why iteration 3 then narrows it with a forbid.

Each run on this page is a real run, with the allowed task only, so you see the requests the agent’s script really sends. It is capped at USD 0.25; the measured run of iteration 1 cost USD 0.0103.

Iteration 1Before the route

What we change. Nothing. The profile is the one in the catch-up block. This run shows what the gateway does with an API request it knows nothing about.

The run.

What this doesRuns the allowed task headless in the box, with the exec proxy as the only MCP server, and writes the stream to a file.

Terminal window
box run ws --no-banner -- --bare --strict-mcp-config --mcp-config exec-proxy.json --tools "" --allowedTools mcp__exec-proxy --model claude-sonnet-5-5 --max-turns 10 --max-budget-usd 0.25 -p "List the Workers on Cloudflare account 0123456789abcdef0123456789abcdef and summarise the current deployment of the Worker box-poc-workshop." --output-format stream-json --verbose < /dev/null > act-c-noroute.jsonl
box run ws --no-banner --
The profile ws, no activity line, and the end of Box’s options.
--bare --strict-mcp-config --mcp-config exec-proxy.json --tools ""
As in the free check: none of your own Claude Code set-up, only the exec proxy, no built-in tools.
--allowedTools mcp__exec-proxy
Pre-approves search and execute, so the headless run never waits for a permission answer.
--model claude-sonnet-5-5
The same model as every act.
--max-turns 10
A hard stop after 10 model turns.
--max-budget-usd 0.25
Claude Code stops when the run has cost USD 0.25. It works only with -p.
-p "List the Workers ..."
The developer’s allowed task, word for word as in every act.
--output-format stream-json --verbose
One JSON event per line, so turns, tokens and the tool results can be read afterwards.
< /dev/null > act-c-noroute.jsonl
An empty input, and the stream in a file you can open with less.

Then read Box’s decisions. The ID is in the line box: policy history: box runs history b-... that box run printed; box runs list ws also lists the runs of the profile, newest first.

What this doesPrints every decision Box made in one run.

Terminal window
box runs history b-0123456789abcdef
b-0123456789abcdef
An example. Use the ID of your own run.

What we see. The proxy starts and runs the script, and both of the script’s connections to api.cloudflare.com are refused before TLS.

What you should see: refused
permit shell:spawn ~/.local/share/mise/installs/node/22.23.4/bin/node mcp_exec-proxy_spawn
permit mcp:call exec-proxy/tools/list mcp_exec-proxy_call
permit mcp:call exec-proxy/execute mcp_exec-proxy_call
deny net:connect api.cloudflare.com:443 <default-deny> no permit matched
deny net:connect api.cloudflare.com:443 <default-deny> no permit matched

The script’s error, as the model received it in the tool result:

Error: Refused by Box egress policy (rule: default-deny) when connecting to the host (net:connect): GET /accounts/0123456789abcdef0123456789abcdef/workers/scripts was not sent. No permit policy matched this request.

The run took 2 turns and cost USD 0.0103.

For the first time in this workshop, Box’s records hold a row for a request to the Cloudflare API itself, not only a tool call. The refusal is <default-deny>: no rule permits the host, and Box refuses whatever no rule permits.

Iteration 2The route

What we add. A route for the Cloudflare API, with its credential.

$HOME/box-ws/profiles/ws/profile.toml
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-"
[mcp.exec-proxy]
type = "stdio"
command = ["${{ home }}/.local/share/mise/installs/node/22.23.4/bin/node", "${{ home }}/box-exec-proxy/proxy/exec-proxy"]
filesystem.read = [
"${{ home }}/.local/share/mise/installs/node/22.23.4",
"${{ home }}/box-exec-proxy/proxy",
"${{ home }}/box-exec-proxy/spec",
]
env = { CLOUDFLARE_ACCOUNT_ID = "0123456789abcdef0123456789abcdef" }
[egress.cloudflare-api]
destinations = ["api.cloudflare.com"]
secret.ref = "env://CLOUDFLARE_API_TOKEN"
  • [egress.cloudflare-api]: a route named cloudflare-api. The name appears in the generated rules.
  • destinations: the one host, without https:// and without a path. Port 443 by default.
  • secret.ref = "env://CLOUDFLARE_API_TOKEN": the real token comes from that variable in the shell where you run box run, the one you read from the keychain on the set-up page. Inside the box, CLOUDFLARE_API_TOKEN holds a stand-in, also in the exec proxy’s environment. The header is Authorization with the prefix Bearer , the defaults, which is what the Cloudflare API expects.

The run. Look at the rules Box now generates. No agent runs.

What this doesPrints the profile as Box resolves it, with the generated box.toml and policy a run would get.

Terminal window
box profile show ws --full
ws
The profile’s name: the folder $HOME/box-ws/profiles/ws/.
--full
Also prints the generated box.toml and policy.dw. Without it, box profile show does not list routes or MCP servers.

What we see. Two new generated rules for the route.

What you should see

In the printed policy.dw, look for the rules with @id("route_cloudflare-api_connect") and @id("route_cloudflare-api_request"). Between them they permit a connection to api.cloudflare.com and every request on it: every method, every path.

Iteration 3Only two reads

What we add. A policy file with one rule, and the line in the profile that names it. Write the file first: a profile that names a missing file does not run.

The new file sits next to the profile, beside the policy files of Parts 3 and 4 if you kept them:

  • Directorybox-ws/
    • Directoryprofiles/
      • Directoryws/
        • profile.toml you edit this
        • api-read-only.dw the rules on each API request
        • no-remote-execute.dw no longer listed
        • operate-tools.dw no longer listed
        • args.dw no longer listed
    • Directorystorage/ kept between runs
      • …
    • Directoryr/ one folder per run
      • …
  • Directoryleaderboard-ops/ the workspace
    • cloudflare-code-mode.json
    • cloudflare-per-endpoint.json
    • exec-proxy.json the exec proxy, for Claude Code
$HOME/box-ws/profiles/ws/api-read-only.dw
// The security engineer's constraints on the workshop app, written for the Cloudflare API
// itself: every request the agent's scripts send to api.cloudflare.com is decided here, by
// method and path. The agent may read the Worker list and the deployments of box-poc-workshop.
// Everything else is refused: the logs, the attendee data in D1, deploys and deletes.
@id("operate_requests_only")
@description("Only two reads are allowed: the Worker list of the workshop account, and the deployments of box-poc-workshop. Every other Cloudflare API request is refused.")
forbid (principal, action == Box::Action::"http:request", resource)
when { context.input.host == "api.cloudflare.com" }
unless {
context.input.intercepted && context.input.method == "GET" && (
context.input.path == "/client/v4/accounts/0123456789abcdef0123456789abcdef/workers/scripts" ||
context.input.path == "/client/v4/accounts/0123456789abcdef0123456789abcdef/workers/scripts/box-poc-workshop/deployments"
)
};
$HOME/box-ws/profiles/ws/profile.toml
packs = ["@box/base"]
policies = ["api-read-only.dw"]
[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-"
[mcp.exec-proxy]
type = "stdio"
command = ["${{ home }}/.local/share/mise/installs/node/22.23.4/bin/node", "${{ home }}/box-exec-proxy/proxy/exec-proxy"]
filesystem.read = [
"${{ home }}/.local/share/mise/installs/node/22.23.4",
"${{ home }}/box-exec-proxy/proxy",
"${{ home }}/box-exec-proxy/spec",
]
env = { CLOUDFLARE_ACCOUNT_ID = "0123456789abcdef0123456789abcdef" }
[egress.cloudflare-api]
destinations = ["api.cloudflare.com"]
secret.ref = "env://CLOUDFLARE_API_TOKEN"

The rule, element by element:

  • @id("operate_requests_only"): the rule’s name. It appears in box runs history and in the refusal the agent reads.
  • @description(...): the reason, in words. The agent receives it with a refusal, so write it for the agent and for the person reading the records.
  • forbid (principal, action == Box::Action::"http:request", resource): the head. This rule can only refuse, and only HTTP requests.
  • when { context.input.host == "api.cloudflare.com" }: it applies to this one host.
  • unless { ... }: the exceptions. The rule does not refuse a request for which this condition is true.
  • context.input.intercepted: the gateway decrypted the request, so the method and the path are the ones really sent.
  • context.input.method == "GET": reads only.
  • The two context.input.path == "..." lines: the two exact paths the task needs, the Worker list of the account and the deployments of box-poc-workshop. The paths start with /client/v4, because policy sees the full URL path. The proxy’s own report and error messages show the path without that prefix, relative to the API’s base URL.

The run. Box checks the profile and its policy file without starting an agent.

What this doesPrints the profile as Box resolves it, and refuses if a policy file is missing or a rule does not load.

Terminal window
box profile show ws
ws
The profile’s name. Without --full, the command prints packs, storage, project and options; it still reads and checks every policy file the profile names.

What we see. The profile is printed with no error. This state, with only the first rule, was not run on its own while the workshop was written; the same rule loads in the next iteration’s file, which was checked.

Iteration 4Give the logs refusal its reason

What we add. A second rule, at the end of the same file.

$HOME/box-ws/profiles/ws/api-read-only.dw
// The security engineer's constraints on the workshop app, written for the Cloudflare API
// itself: every request the agent's scripts send to api.cloudflare.com is decided here, by
// method and path. The agent may read the Worker list and the deployments of box-poc-workshop.
// Everything else is refused: the logs, the attendee data in D1, deploys and deletes.
@id("operate_requests_only")
@description("Only two reads are allowed: the Worker list of the workshop account, and the deployments of box-poc-workshop. Every other Cloudflare API request is refused.")
forbid (principal, action == Box::Action::"http:request", resource)
when { context.input.host == "api.cloudflare.com" }
unless {
context.input.intercepted && context.input.method == "GET" && (
context.input.path == "/client/v4/accounts/0123456789abcdef0123456789abcdef/workers/scripts" ||
context.input.path == "/client/v4/accounts/0123456789abcdef0123456789abcdef/workers/scripts/box-poc-workshop/deployments"
)
};
@id("no_worker_logs")
@description("The Worker's logs hold attendee names and email addresses. The agent may not read them.")
forbid (principal, action == Box::Action::"http:request", resource)
when { context.input.host == "api.cloudflare.com" && context.input.path like "*/workers/observability/*" };
  • context.input.path like "*/workers/observability/*": a pattern, where * stands for any text. The Workers Logs routes of the Cloudflare API that read log content sit under /workers/observability/: the log query, live tail, and the keys and values of the logs. A script’s tail sessions have a path of their own, under /workers/scripts/<name>/tails/; the first rule refuses those.

The run. The same check as in iteration 3.

What this doesChecks the profile and its policy file again.

Terminal window
box profile show ws
ws
The profile’s name.

What we see. The profile is printed with no error: both rules load. This was checked while the workshop was written.

You will see the refusal of the logs query in act c. Here is what to look for, and where.

  • In the run’s history. A refused request is one row: deny, the action http:request, the resource host:port/path, the rule’s id and the reason a forbid rule matched. Two filters of box runs history help: --deny prints only refusals, and --action http:request prints only API requests.
  • In what the agent receives. The gateway answers 403, and the request never leaves the box. The body is the refusal text, in the form http:request gate: policy denied this operation on '<host:port/path>' [policy: <id>]: <description> (Box docs, policy.md). The proxy turns it into the error the script throws, starting Refused by Box egress policy (rule: <id>).
  • In the records file. $HOME/box-ws/r/<id>/records.jsonl holds every decision as OpenTelemetry JSON. When two rules match, as operate_requests_only and no_worker_logs will, box runs history names one of them (which one differs between runs), and the record names both in strands.box.policy.determining.ids. Open the file with less and search for either name.

What this doesPrints only the API requests Box refused in one run.

Terminal window
box runs history b-0123456789abcdef --deny --action http:request
b-0123456789abcdef
An example ID. Use your own run’s.
--deny
Only refusals.
--action http:request
Only decisions on HTTP requests, so the agent’s model traffic and the MCP rows drop out.
Security engineerWhat can the policy see, decide and record?

You now write the constraint where the effect happens: on the request to Cloudflare. The rule does not depend on which tool the model picks, which script it writes or which operation name it finds; only on method, host and path. You can read the rule aloud: refuse everything on api.cloudflare.com except two GETs. What it cannot see is the request body and the response. An allowed read can still return personal data, as act c will show.

DeveloperWhat can the agent still do, and what does it cost?

The agent’s tools do not change: still search and execute. Nothing is added to the model’s context for these rules. A refused request costs a turn and comes back with a reason the agent can read and pass on. The price is that each extra read the team needs is a change to the security engineer’s file.

  • The gateway decides each connection (net:connect) and each request (http:request) on its own.
  • A route writes the permits for its host and attaches the credential; it opens every method and path.
  • A forbid ... unless narrows the route to the exact requests the task needs. A permit cannot narrow a permit.
  • Policy sees the full path, /client/v4/..., without the query, and never the body.
  • A second rule that changes no decision can still carry the reason the story wants recorded.

Read moreThe actions and their fields, including net:connect and http:requestBox docs

Read morePolicy: how a denial reads, and “Forbid one URL path on a host”Box docs

Read moreProfile reference: routes and other hostsBox docs

Read moreEgress credential configurationBox docs

Read moreThe Cedar policy languageCedar docs

Read moreWorkers Logs, what the refused routes holdCloudflare docs

Read morePolicy basics: how forbid and permit combineThis workshop