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.
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" }{ "mcpServers": { "exec-proxy": { "command": "node", "args": ["${HOME}/box-exec-proxy/proxy/exec-proxy"] } }}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.
From a tool call to an API request
Section titled “From a tool call to an API request”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.
How a rule names a request
Section titled “How a rule names a request”The egress gateway decides each request twice (Box docs, policy/actions.md):
net:connect, once per connection, before TLS. It knows thehostand theport. 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,POSTand 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%2Fas they are.body_bytes: the length of the body. The body itself is not visible to policy.intercepted:truewhen 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.
Write the rules, one at a time
Section titled “Write the rules, one at a time”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.
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.
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.jsonlbox run ws --no-banner --ws, no activity line, and the end of Box’s options.--bare --strict-mcp-config --mcp-config exec-proxy.json --tools ""--allowedTools mcp__exec-proxysearch and execute, so the headless run never waits for a permission answer.--model claude-sonnet-5-5--max-turns 10--max-budget-usd 0.25-p.-p "List the Workers ..."--output-format stream-json --verbose< /dev/null > act-c-noroute.jsonlless.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.
box runs history b-0123456789abcdefb-0123456789abcdefWhat we see. The proxy starts and runs the script, and both of the script’s connections to api.cloudflare.com are refused before TLS.
permit shell:spawn ~/.local/share/mise/installs/node/22.23.4/bin/node mcp_exec-proxy_spawnpermit mcp:call exec-proxy/tools/list mcp_exec-proxy_callpermit mcp:call exec-proxy/execute mcp_exec-proxy_calldeny net:connect api.cloudflare.com:443 <default-deny> no permit matcheddeny net:connect api.cloudflare.com:443 <default-deny> no permit matchedThe 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.
What we add. A route for the Cloudflare API, with its credential.
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 namedcloudflare-api. The name appears in the generated rules.destinations: the one host, withouthttps://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 runbox run, the one you read from the keychain on the set-up page. Inside the box,CLOUDFLARE_API_TOKENholds a stand-in, also in the exec proxy’s environment. The header isAuthorizationwith the prefixBearer, 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.
box profile show ws --fullws$HOME/box-ws/profiles/ws/.--fullbox.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.
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.
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
// 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" )};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 inbox runs historyand 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 ofbox-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.
box profile show wsws--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.
What we add. A second rule, at the end of the same file.
// 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.
box profile show wswsWhat we see. The profile is printed with no error: both rules load. This was checked while the workshop was written.
How a refusal looks in the records
Section titled “How a refusal looks in the records”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 actionhttp:request, the resourcehost:port/path, the rule’s id and the reasona forbid rule matched. Two filters ofbox runs historyhelp:--denyprints only refusals, and--action http:requestprints 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 formhttp: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, startingRefused by Box egress policy (rule: <id>). - In the records file.
$HOME/box-ws/r/<id>/records.jsonlholds every decision as OpenTelemetry JSON. When two rules match, asoperate_requests_onlyandno_worker_logswill,box runs historynames one of them (which one differs between runs), and the record names both instrands.box.policy.determining.ids. Open the file withlessand search for either name.
What this doesPrints only the API requests Box refused in one run.
box runs history b-0123456789abcdef --deny --action http:requestb-0123456789abcdef--deny--action http:requestThe two seats
Section titled “The two seats”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.
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.
What to remember
Section titled “What to remember”- 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 ... unlessnarrows 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