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

Act b3-args: one tool, one account

In this act you add a rule on a tool’s argument: workers_deployments_list may run, but only for the workshop’s Cloudflare account. You will ask for the deployments on another account and on the workshop’s, in one sentence, and see the first call refused by your rule and the second one run.

After act b3 the agent may read the Workers and their deployments, and may not read the logs or the attendee registry of the workshop progress tracker. But the token the team gave it is broad, and the allow-list says nothing about which account a listed tool is used on. The security engineer’s next constraint: the agent operates this app, on this account (0123456789abcdef0123456789abcdef), and nothing else. In the story’s terms, a deployments list of some other team’s Worker is not the agent’s business.

Your files at this point
$HOME/box-ws/profiles/ws/profile.toml
packs = ["@box/base"]
policies = ["operate-tools.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"
MCP_TIMEOUT = "300000"
[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"
$HOME/box-ws/profiles/ws/operate-tools.dw
// The security engineer's constraint, written for the one-tool-per-operation server: the agent
// may run only the tools that read the Workers and their deployments. Every other tool of the
// 3,053 is refused, among them o11y_telemetry_query (the Worker's logs, which hold attendee
// names and emails), d1_query (the attendee registry) and every deploy or delete tool.
@id("operate_tools_only")
@description("Only the tools that read the Workers and their deployments may run. The Worker's logs and the attendee data hold names and emails, and the agent may not deploy or delete.")
forbid (principal, action == Box::Action::"mcp:call", resource)
when { context.input.server == "cloudflare" && context.input.method == "tools/call" }
unless {
context.input has tool && [
"workers_legacy_scripts_list",
"workers_legacy_scripts_get",
"workers_legacy_scripts_scriptAndVersionSettings_get",
"workers_legacy_scripts_content_get",
"workers_legacy_scripts_versions_list",
"workers_deployments_list"
].contains(context.input.tool)
};
$HOME/leaderboard-ops/cloudflare-per-endpoint.json
{
"mcpServers": {
"cloudflare": {
"type": "http",
"url": "https://mcp.cloudflare.com/mcp?codemode=false",
"headers": { "Authorization": "Bearer ${CLOUDFLARE_MCP_TOKEN}" }
}
}
}

no-remote-execute.dw and cloudflare-code-mode.json from earlier acts may stay on disk; this act does not use them.

Architecture, stage 4 of 5, with the path of act b3-argsPieces: macOS keychain, Developer's terminal, Claude Code, Contained filesystem view, 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: Tool catalog, Cloudflare MCP server. workers_deployments_list is permitted on the sample app's account and refused on any other account. A full text description follows the diagram.The boxAgent's sandboxTrusted processbox runstartsmacOS keychainthree secretsDeveloper'sterminalClaude Codethe agentContainedfilesystem viewbox 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 toolnewPolicy engineCedar and Dogwood policy files (.dw)Recordsrecords.jsonl and the run's historyAnthropic APIapi.anthropic.comCloudflare MCP serverper-endpoint mode:3,053 toolschangedCloudflare APIapi.cloudflare.comSample appWorker box-poc-workshop,its D1, KV andWorkers Logsholds names and email addressesnew at this stagepath of act b3-argsother account refused

Act b3-args: one tool on one account. workers_deployments_list is permitted on the sample app's account and refused on any other account.

Text description of the diagram

Stage 4 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
  • the staged tool catalog: Box types each tool from the server's tools/list before the agent may call it (new at this stage)
  • 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 (changed at this stage: it now runs in per-endpoint mode)
  • 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 b3-args:

  1. As in act b3, the catalog gives the policy engine a typed schema for each tool.
  2. A rule reads the tool call's account_id argument.
  3. The call with the sample app's account is permitted and reaches the Cloudflare API.
  4. The same call with another account is refused at the gateway and recorded.

Outcome: workers_deployments_list is permitted on the sample app's account and refused on any other account.

The pieces are those of act b3. What is new is the decision: the policy engine reads the tool call’s account_id argument from the typed schema, and the same tool is permitted for one account and refused for another.

Iteration 1One tool, one account

What we add. A second policy file, $HOME/box-ws/profiles/ws/args.dw, next to the allow-list:

  • Directorybox-ws/
    • Directoryprofiles/
      • Directoryws/
        • profile.toml you edit this
        • no-remote-execute.dw no longer listed
        • operate-tools.dw the allow-list
        • args.dw the argument rule
    • Directorystorage/ kept between runs
      • …
    • Directoryr/ one folder per run
      • …
  • Directoryleaderboard-ops/ the workspace
    • cloudflare-code-mode.json
    • cloudflare-per-endpoint.json

Build it in this order (each element is explained on Rules on a tool’s arguments):

  1. The comment: the constraint, and where the account is found in the call.
  2. The id and the description, in the story’s words: this is constraint 5 of the sample app, “This account only”. The id is what the records show; the description is what the agent reads when it is refused.
  3. The effect and scope: forbid on the per-tool action cloudflare::Action::"workers_deployments_list", the only decision that sees the tool’s arguments.
  4. unless: the call carries an account_id in its path argument (has), and that account is the workshop’s.
$HOME/box-ws/profiles/ws/args.dw
// The security engineer's constraint 5, "This account only", for the one-tool-per-operation server:
// workers_deployments_list may run, but only on the workshop's own Cloudflare account.
// Box types the tool's arguments from tools/list; the account is the path argument account_id.
@id("this_account_only")
@description("The agent operates the workshop progress tracker on its own account, 0123456789abcdef0123456789abcdef, and nowhere else.")
forbid (principal, action == cloudflare::Action::"workers_deployments_list", resource)
unless { context.input.path has account_id && context.input.path.account_id == "0123456789abcdef0123456789abcdef" };

Then list it in the profile, after the allow-list:

$HOME/box-ws/profiles/ws/profile.toml (first two lines)
packs = ["@box/base"]
policies = ["operate-tools.dw", "args.dw"]

The run. box profile show ws passes and lists both files. It cannot check the new rule: a per-tool rule loads only once the catalog is staged. So run the Part 4 free check.

What this doesStarts the box, lets Claude Code connect the per-endpoint server, and stops at the first model call. Nothing is billed.

Terminal window
ANTHROPIC_API_KEY=sk-ant-preflight-invalid-key box run ws --no-banner -- --setting-sources "" --strict-mcp-config --mcp-config cloudflare-per-endpoint.json --tools ToolSearch --allowedTools mcp__cloudflare,ToolSearch --model claude-sonnet-5-5 --max-turns 1 -p "Say hello." --output-format stream-json --verbose < /dev/null > check.jsonl
(every flag)
As in iteration 2 of act b3: the invalid key for this one command, profile ws, Claude Code with no settings files, only the per-endpoint server, ToolSearch as the one built-in tool, one turn, the event stream to check.jsonl.

What we see. After about a minute the server is connected with 3,053 tools, and the terminal shows no per-tool warning: the rule loaded when the catalog was staged. In the two checks made for this page the hand-over took 64.0 and 70.8 seconds, and the run 67 and 75 seconds.

What you should see: permitted
"name":"cloudflare","status":"connected"

The act is one sentence that asks for the same tool twice: first on a made-up account, then on the workshop’s. fedcba9876543210fedcba9876543210 is a made-up account id; it belongs to nobody. The recorded runs used a different made-up id, 0123456789abcdef0123456789abcdef, which this site now uses as the stand-in for the workshop’s own account.

What this doesStarts Claude Code in the box with the per-endpoint server, asking you before any tool that is not pre-approved.

Terminal window
box run ws -- --setting-sources "" --strict-mcp-config --mcp-config cloudflare-per-endpoint.json --tools ToolSearch --allowedTools mcp__cloudflare,ToolSearch --model claude-sonnet-5-5 --max-turns 12 --permission-mode manual
(every flag)
As in the interactive run of act b3. Wait about a minute for the catalog before you type.
Two accounts, one tool
Using only the workers_deployments_list tool of the cloudflare MCP server, list the deployments of the Worker box-poc-workshop first on account fedcba9876543210fedcba9876543210 and then on account 0123456789abcdef0123456789abcdef.

This sentence was run twice as a paid verification run on the workshop’s build, with your file as this page builds it: 4 turns and about USD 0.22 each, as Claude Code reported them. Only turns and cost were recorded for those runs. The run whose decisions and tokens are shown below used a sentence that was not recorded; its calls had this shape: one workers_deployments_list call with account_id fedcba9876543210fedcba9876543210, then one with 0123456789abcdef0123456789abcdef, both with script_name box-poc-workshop.

box runs history <box ID> for the measured run on the workshop’s build (time and reason columns, net:connect rows and the gateway’s http:request rows left out). The measured run used the kit’s version of this rule, the same forbid ... unless under the id logstoolsargs_deployments_poc_account.

Below, the RULE column shows your rule’s id in place of the kit’s. The last verification run for this site used your file on the workshop’s build and showed the same two decisions: the other account refused by this_account_only, then the workshop’s account permitted.

What you should see: one refused, one permitted
permit mcp:call cloudflare/resources/list mcp_cloudflare_call
permit mcp:call cloudflare/tools/list mcp_cloudflare_call
deny workers_deployments_list cloudflare/workers_deployments_list this_account_only
permit mcp:call cloudflare/workers_deployments_list mcp_cloudflare_call

The refusal is a per-tool decision: the ACTION column holds the tool’s name and RULE your rule’s id. The first call got past operate_tools_only (the tool is on the list) and was stopped by the argument rule. The second call, with the workshop’s account, was permitted.

The shape of the refusal was measured with the kit’s rule.

The text below is the same refusal with your rule’s id and description. The last verification run for this site, with your file, received this text.

The refusal, as the model sees it (your rule)
per-tool gate (cloudflare::Action::"workers_deployments_list"): policy denied this operation on 'cloudflare/workers_deployments_list' [policy: this_account_only]: The agent operates the workshop progress tracker on its own account, 0123456789abcdef0123456789abcdef, and nowhere else.

The agent said it could list the deployments on only one of the two accounts. For fedcba9876543210fedcba9876543210: denied by the argument rule (in your file, this_account_only), which allows the tool only on the workshop’s account; it did not try to work around it, and said the policy would have to change. For the workshop’s account: four deployments of box-poc-workshop, the newest (2026-11-14 14:17 UTC) serving all traffic, each sending 100 percent to one version, all made with wrangler by the same author, whose email address (<redacted>) the answer printed.

Security engineerWhat can the policy see, decide and record?

The policy now decides on what a tool is called with, not just its name: the same tool is permitted for the workshop’s account and refused for any other, and the records name the rule. If the rule had failed to load, every call to the tool would have been refused. What the rule cannot do is look at the answer: the permitted deployments list carried the deployer’s email address, and it reached the agent.

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

For the right account nothing changed: the call ran and the answer was complete. For the wrong account the agent got a clear refusal naming the rule. The run cost $0.2354 and took 85 seconds, most of it the catalog wait, the same as any per-endpoint run.

The takeaway: a rule on a typed argument narrows an allowed tool to one account with one line, and refuses when it cannot decide, but it decides the request, never the data that comes back.

Measured, act b3-args, task: two accounts, one tool
Turns
4
Tokens
320,678 in, 1,157 out
Cost
$0.2354
Wall time
85 s
Box build
pkg-fix

One run, headless, on the workshop’s build (pkg-fix), with the kit’s allow-list (the same six tools under another id) and this argument rule. Claude Code’s own time was 18.0 seconds of the 85. See Builds and gaps.

What this doesDeletes this act's stream files and the free check's stream. A stream holds whatever the agent read; in the measured run that included the deployer's email address.

Terminal window
rm -f act-b3-args.jsonl check.jsonl
-f
No question, and no error if a file is missing.
(the files)
Named one by one rather than with a pattern, so no other act’s file goes with them.

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.

Terminal window
ls -R "$BOX_HOME/storage/ws/default/agent/config/projects"
-R
Lists the subfolders and their files too.

What this doesDeletes every transcript kept in the profile's storage. Run it after the run has ended.

Terminal window
rm -r "$BOX_HOME/storage/ws/default/agent/config/projects"
-r
Removes the folder with everything in it. Check the path before you press Enter.
  • An argument rule names the tool in its head and reads context.input.<argument>: here context.input.path.account_id.
  • has before the comparison, and forbid ... unless, so a missing or wrong account is refused and a broken rule fails closed.
  • box profile show cannot check a per-tool rule. The free check can: no per-tool warning means it loaded.
  • A rule decides each request. What a permitted request returns, such as a deployer’s email, is not the policy’s to see.

Read moreWrite policy for an MCP server: rules on tool argumentsBox docs

Read moreHow Box discovers tools and loads per-tool rulesBox docs

Read moreAPI reference: List DeploymentsCloudflare docs

Read moreRules on a tool’s argumentsThis workshop