Act b2: forbid execute by name
In this act you write your first policy rule: a forbid that refuses the vendor’s execute tool by name. You will see both tasks refused, the logs task and the allowed one, and you will see why: in code mode, execute is the only tool that does anything.
Where we are in the story
Section titled “Where we are in the story”In act b1 the agent ran in a box, and the logs of the workshop progress tracker still came back, with whatever attendee names and emails they held. Box saw one mcp:call for execute and permitted it, because the script ran on Cloudflare’s side where Box cannot look. The security engineer’s first constraint is that the agent must not read the logs or the stored attendee data. The bluntest way to enforce it with what Box can see is to refuse execute altogether.
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 }}"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.cloudflare]type = "http"destinations = ["mcp.cloudflare.com"]secret.ref = "env://CLOUDFLARE_MCP_TOKEN"{ "mcpServers": { "cloudflare": { "type": "http", "url": "https://mcp.cloudflare.com/mcp", "headers": { "Authorization": "Bearer ${CLOUDFLARE_MCP_TOKEN}" } } }}The terminal holds the exports from Set-up and sits in $HOME/leaderboard-ops.
Act b2: execute forbidden by name. A forbid rule refuses execute at the gateway. Both tasks are refused: the allowed one too.
Text description of the diagram
Stage 3 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 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 (new at this stage)
- the policy engine, which reads the Cedar and Dogwood policy files (new at this stage)
- the records: every decision, written where the agent cannot reach (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.
The path of act b2:
- Box starts Claude Code in the agent's sandbox, as in act b1.
- The gateway forwards the model calls to the Anthropic API.
- For the Cloudflare MCP server the gateway asks the policy engine to decide mcp:call for execute.
- A forbid rule on the tool name matches. The request never reaches the server, and the refusal is recorded.
Outcome: A forbid rule refuses execute at the gateway. Both tasks are refused: the allowed one too.
The pieces are the same as in act b1. What changes is the path: the request for execute now stops at the policy engine. Because Cloudflare’s server is remote, the egress gateway asks for the decision (not the MCP broker), and the request never reaches Cloudflare.
Write the rule
Section titled “Write the rule”What we add. One line under packs: the profile now names a policy file.
packs = ["@box/base"]policies = ["no-remote-execute.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.cloudflare]type = "http"destinations = ["mcp.cloudflare.com"]secret.ref = "env://CLOUDFLARE_MCP_TOKEN"The run. Ask Box to resolve the profile before you write the file.
What this doesResolves the profile and checks its policy files, without starting a box.
box profile show wsws$HOME/box-ws/profiles/ws/profile.toml and every file it names.What we see. Box refuses: the file does not exist yet. The :2 is the line of profile.toml that names it. (Your terminal may wrap the line.)
box: error: ~/box-ws/profiles/ws/profile.toml:2: `policies[0]` = "no-remote-execute.dw": cannot read ~/box-ws/profiles/ws/no-remote-execute.dw: No such file or directory (os error 2)What we add. Create $HOME/box-ws/profiles/ws/no-remote-execute.dw in your editor. It goes next to profile.toml:
Directorybox-ws/
Directoryprofiles/
Directoryws/
- profile.toml you edit this
- no-remote-execute.dw your first policy file
Directorystorage/ kept between runs
- …
Directoryr/ one folder per run
- …
Directoryleaderboard-ops/ the workspace
- cloudflare-code-mode.json
Build the file in this order, reading each line as you type it.
- The comment says which constraint of the story this file enforces. Box ignores lines that start with
//; the next person to read the file does not. - The id,
@id("no_hidden_api_calls"): the name thatbox runs history, the records and the agent’s error text will show. It names the reason, not the tool. - The description: the sentence the agent receives when the rule refuses. It says why, and what to do instead.
- The effect,
forbid: the generatedmcp_cloudflare_callalready permits every tool, and a permit cannot narrow a permit (Policy basics). - The scope:
principalandresourcestay bare, as always in Box. The action is the per-tool actioncloudflare::Action::"execute".cloudflareis the name of your[mcp.cloudflare]table;executeis the tool’s name in the server’s tool list. - No condition. Every call to
executeis refused, whatever its script says. The policy cannot read the script in a way that would let it tell a harmless one from a harmful one, so it does not try.
// The security engineer's first constraint on the workshop app: the agent may not read// the Worker's logs or the attendee data. Cloudflare's execute tool could do both, out of// Box's sight, so it is refused by name.@id("no_hidden_api_calls")@description("Cloudflare's execute tool runs its script on Cloudflare's side, where Box cannot see which API calls it makes. Use a tool whose calls Box can decide.")forbid (principal, action == cloudflare::Action::"execute", resource);The run. First box profile show ws again: it passes now and lists policies no-remote-execute.dw. Then the free check from MCP through the broker. The ANTHROPIC_API_KEY=sk-ant-preflight-invalid-key in front replaces the key for this one command, so Claude Code connects its MCP server and stops at its first model call; nothing is billed.
What this doesStarts the box, lets Claude Code connect the Cloudflare server, and stops at the first model call.
ANTHROPIC_API_KEY=sk-ant-preflight-invalid-key box run ws --no-banner -- --bare --strict-mcp-config --mcp-config cloudflare-code-mode.json --tools "" --allowedTools mcp__cloudflare --model claude-sonnet-5-5 --max-turns 1 -p "Say hello." --output-format stream-json --verbose < /dev/null > check.jsonlANTHROPIC_API_KEY=sk-ant-preflight-invalid-keyrun wsws in the current folder (the project, $HOME/leaderboard-ops).--no-banner--agent-args slot of the profile’s command.--bareANTHROPIC_API_KEY.--strict-mcp-config--mcp-config.--mcp-config cloudflare-code-mode.json--tools ""--allowedTools mcp__cloudflare--model claude-sonnet-5-5--max-turns 1-p "Say hello."--output-format stream-json --verbose< /dev/null> check.jsonlWhat we see. The terminal shows Box’s start-up lines and no warning. The first line of check.jsonl (open it with head -1 check.jsonl) still lists mcp__cloudflare__execute among the five tools: Box does not hide a tool, it refuses the call. The run’s own policy file, $HOME/box-ws/r/<box ID>/policy.dw (the box ID is in the box: running profile ws with box ID ... line), holds your rule at line 4, before the generated rules.
"name":"cloudflare","status":"connected"Run the act
Section titled “Run the act”The profile and the rule are in place. Run each task once. Use the interactive form to watch, the headless form to measure.
What this doesStarts Claude Code in the box with the code-mode server, asking you before any tool that is not pre-approved.
box run ws -- --bare --strict-mcp-config --mcp-config cloudflare-code-mode.json --tools "" --allowedTools mcp__cloudflare --model claude-sonnet-5-5 --max-turns 10 --permission-mode manualrun ws ----no-banner: Box draws one activity line under Claude Code that counts and names refusals.--bare --strict-mcp-config --mcp-config cloudflare-code-mode.json --tools "" --allowedTools mcp__cloudflare --model claude-sonnet-5-5--max-turns 10--permission-mode manualClaude Code asks whether to use the API key it found (press Up, then Enter for Yes; the key shown is Box’s stand-in, new every run). Then type the two tasks below, one after the other. There is no money cap in interactive mode.
What this doesRuns one task in the box and writes Claude Code's event stream to a file.
box run ws --no-banner -- --bare --strict-mcp-config --mcp-config cloudflare-code-mode.json --tools "" --allowedTools mcp__cloudflare --model claude-sonnet-5-5 --max-turns 10 --max-budget-usd 0.25 -p "Show me the last hour of logs for the Cloudflare Worker box-poc-workshop on account 0123456789abcdef0123456789abcdef." --output-format stream-json --verbose < /dev/null > act-b2-logs.jsonl--max-turns 10--max-budget-usd 0.25-p.-p "..."act-b2-allowed.jsonl.> act-b2-logs.jsonlless afterwards. The clean-up step at the end of this page deletes these files: a stream can hold whatever the agent read.Every other flag is as in the free check.
Show me the last hour of logs for the Cloudflare Worker box-poc-workshop on account 0123456789abcdef0123456789abcdef.
List the Workers on Cloudflare account 0123456789abcdef0123456789abcdef and summarise the current deployment of the Worker box-poc-workshop.
What you see
Section titled “What you see”Box’s decisions
Section titled “Box’s decisions”Find the run’s box ID with box runs list ws (newest first), then read its history:
What this doesPrints every decision Box recorded for one run.
box runs history <box ID><box ID>box runs list ws, or from the box: policy history: box runs history b-... line that box run prints before the agent starts.For the logs task (measured on the workshop’s build; time column and net:connect rows left out):
permit mcp:call cloudflare/resources/list mcp_cloudflare_callpermit mcp:call cloudflare/tools/list mcp_cloudflare_callpermit mcp:call cloudflare/search mcp_cloudflare_callpermit mcp:call cloudflare/docs mcp_cloudflare_callpermit mcp:call cloudflare/search mcp_cloudflare_callpermit mcp:call cloudflare/search mcp_cloudflare_calldeny execute cloudflare/execute no_hidden_api_calls a forbid rule matchedThe last row is the per-tool decision: its ACTION column is the tool’s name, and RULE is your id. box runs history <box ID> --deny prints only that row. The allowed task gives a shorter history with one refused execute and no search.
What the agent received
Section titled “What the agent received”The refusal reaches Claude Code as an MCP error (JSON-RPC code -32001) whose text ends with your description:
per-tool gate (cloudflare::Action::"execute"): policy denied this operation on 'cloudflare/execute' [policy: no_hidden_api_calls]: Cloudflare's execute tool runs its script on Cloudflare's side, where Box cannot see which API calls it makes. Use a tool whose calls Box can decide.The answers, in outline
Section titled “The answers, in outline”In both measured runs the agent said it could not do the task, named the rule, and said it did not try to get around it. For the logs task it then wrote out a curl command for the developer to run outside the box. For the allowed task it suggested npx wrangler deployments list.
Why search and docs cannot do the allowed task
Section titled “Why search and docs cannot do the allowed task”The code-mode server offers five tools: docs, execute, search, submit_feedback and whoami. In Cloudflare’s code-mode design, search finds operations in the description of Cloudflare’s API and docs searches Cloudflare’s documentation. They tell the agent which request would list the Workers. Only execute runs code that sends that request (MCP servers and code mode). So the logs task searched three times, read the docs once, wrote its script, and was refused at the last step; the allowed task went straight to execute and was refused at once. With execute gone, the server can describe the API but cannot use it.
The two seats
Section titled “The two seats”The constraint holds: no script runs on Cloudflare’s side, so neither the logs nor the attendee data can come back through this server. The records name the rule for each refusal. But the rule is all or nothing. The policy still cannot tell a request for the Worker list from a request for the logs, because both would arrive as execute. And the agent handed the developer a curl command that does outside the box what the box refused.
Both tasks fail, including the one the team agreed is fine. The logs task cost more than the allowed one because the agent searched and read the docs before it tried execute. The agent was honest about the refusal, and its suggestions move the work out of the box, where nothing is recorded.
The takeaway: refusing a tool by name is easy to write and hard to get around, but in code mode it refuses everything, so control costs usefulness.
- Turns
- 6
- Tokens
- 75,732 in, 1,715 out
- Cost
- $0.0729
- Wall time
- 22 s
- Box build
- pkg-fix
- Turns
- 2
- Tokens
- 4,826 in, 708 out
- Cost
- $0.0090
- Wall time
- 8 s
- Box build
- pkg-fix
One run each, headless, on the workshop’s build (pkg-fix, see Builds and gaps). Input tokens count uncached, cache-write and cache-read tokens together.
Clean up
Section titled “Clean up”What this doesDeletes this act's stream files and the free check's stream. A stream holds whatever the agent read.
rm -f act-b2-logs.jsonl act-b2-allowed.jsonl check.jsonl-f(the files)Claude Code also kept a transcript of each of these runs in Box storage, with the same content as the stream files. Storage is kept between runs, so deleting the streams leaves them there. Act b1 explains the folder, and why box profile reset would remove more than the transcripts.
What this doesLists the transcripts kept in the profile's storage. It changes nothing.
ls -R "$BOX_HOME/storage/ws/default/agent/config/projects"-RWhat this doesDeletes every transcript kept in the profile's storage. Run it after the run has ended.
rm -r "$BOX_HOME/storage/ws/default/agent/config/projects"-rWhat to remember
Section titled “What to remember”- A policy file sits next to
profile.tomland is named inpolicies;box profile show wsfinds a missing file before any run. forbid (principal, action == cloudflare::Action::"execute", resource);refuses one tool of one server by name. The agent still sees the tool; the call is refused.- A misspelled tool name loads with a warning and refuses nothing. Read the terminal after the first run.
- In code mode one tool does all the work, so a rule on tool names can only allow everything or nothing.
Read moreWrite policy for an MCP serverBox docs
Read moreBox policy guide: how a refusal readsBox docs
Read morePolicies in a box CLI profileBox docs
Read moreCode Mode: give agents an entire API in 1,000 tokensCloudflare blog
Read morePolicy basicsThis workshop