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

Agent in a Box: sandboxing AI coding agents with Strands Box

One sandbox, two seats: the security engineer's and the developer's.

This site explains how a sandbox for an AI coding agent works. It does that by solving one problem in stages, and by looking at every stage from two seats. After this page you will know the problem, who the site is written for, and how its pages fit together.

  1. A developer wants Claude Code, a coding agent, to help operate a small app that runs on Cloudflare.
  2. The agent reaches Cloudflare through an MCP server: a program that offers an agent a set of tools it can call.
  3. Cloudflare’s own MCP server offers one generic tool, execute, that runs a script against the whole Cloudflare API.
  4. A security engineer must be able to allow or refuse each API operation, because the app’s logs and database hold people’s names and email addresses.
  5. We put the agent in a sandbox with Strands Box and find out, step by step, where a policy can make that decision and what each choice costs.

A sandbox is a boundary around a program that decides what it may read, write, run and reach on the network. Strands Box (Box for short) is an open source sandbox engine for AI agents. You drive it with the box CLI, the box command.

Every stage is told twice, once from each seat. The two cards below come back on every concept and act page. Only the requirements, set-up, builds-and-gaps and further-reading pages have none.

Security engineerWhat can the policy see, decide and record?

You decide what the agent may do. On each page you ask: what can the policy see, what can it decide, and what does it write down so that I can check later?

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

You want the agent to get work done. On each page you ask: what can the agent still do, how many tokens does it spend, and how much friction does the set-up add?

The site is for people who want to understand the moving parts and the trade-offs. It is not a quick way to run a demo. Every command and every setting is explained: what it does, why it is chosen here, what the alternative would do, and where to read more.

  • What a box contains: the agent’s files, its network, its secrets and its tools, and which part of Box enforces each.
  • How a Box profile and a policy file are built up, one setting and one rule at a time.
  • What Box can see of an MCP tool call, and why a generic execute tool hides the API calls that matter.
  • Three ways to put a decision on each Cloudflare operation (refuse the tool, one tool per operation, or decide each HTTP request) and what each costs the developer.
  • Where Box’s records of decisions live, and how to read them with the box CLI.
  • Which parts of this set-up are local builds or proposals, and what a released Box still lacks.

Start sets the scene. Five parts each answer one question, and each ends in one or two acts. Results puts the acts side by side.

The badge after a page’s name in the sidebar says what kind of page it is.

Badge What the page does
Concept Explains one idea when the story first needs it, and shows it in this workshop’s real files or output.
Hands-on Builds part of the profile or the policy in small iterations. Each iteration is one change, one command, what you see, and why.
Act a to Act c One of the six moments where the agent runs a task. The page gathers your files, launches the agent, and shows what came back and what Box decided.

Each hands-on and act page starts with a collapsed block called “your files at this point”. It holds the complete files, so if you get lost you can paste them into your editor and carry on.

Act Part The set-up
a 1 Claude Code and Cloudflare’s MCP server, no box.
b1 2 The same server, with the agent inside a box. execute is permitted.
b2 3 A policy rule refuses execute by name.
b3 4 The server offers one tool per API operation; a rule allows a short list of tool names.
b3-args 4 A rule on one tool’s arguments: the tool may run on one account only.
c 5 A local MCP server inside the box runs the agent’s script; every API request it makes is decided at the box’s network gateway.

What each act shows is on the story page.

The architecture diagram starts with the few pieces of a set-up without a sandbox. Each part adds pieces, and each page shows the diagram at its stage with the new pieces marked. This is the starting picture:

Architecture, stage 1 of 5Pieces: macOS keychain, Developer's terminal, Claude Code, Anthropic API, Cloudflare MCP server, Cloudflare API, Sample app. A full text description follows the diagram.real tokenmacOS keychainthree secretsDeveloper'sterminalClaude Codethe agentAnthropic APIapi.anthropic.comCloudflare MCP servercode mode: search, executeCloudflare APIapi.cloudflare.comSample appWorker box-poc-workshop,its D1, KV andWorkers Logsholds names and email addresses

Stage 1: the developer's terminal, Claude Code, Cloudflare's MCP server and API, and the sample app. No sandbox yet.

Text description of the diagram

Stage 1 of 5. No sandbox yet.

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 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

Every piece keeps its place on later pages, so you can watch the box appear around Claude Code in Part 2 and fill up in Parts 3 to 5.

There are no launcher scripts on this site. Every step is one command that you type, and every flag is explained under it. The Box profile and the policy files are written out by you, one setting or one rule at a time, starting from the smallest file that runs.

Most steps are checked with a free check: the command runs with an invalid model key, so Claude Code connects its MCP server and stops at its first model call. Nothing is billed. The acts themselves are real runs, which cost money; each act page says what one run cost when it was measured.

Reading time was not measured. What was measured is how long one run of each act took on the clock (from Measurements):

Part Pages Act Wall time of one run, as measured
1 2 a 10 s (allowed task), 13 s (logs task); no box, Claude Code 2.1.325
2 5 b1 22 s (logs task)
3 2 b2 17 s (logs task)
4 4 b3, b3-args 75 s to 85 s per run; most of it is Box preparing the server’s 3,053 tools before the agent may use them
5 3 c 10 s (allowed task), 19 s (logs task)

The times for b1 to c come from local box builds made before a released Box had what this workshop needs (the build this site uses among them), with Claude Code 2.1.330. Builds and gaps explains the builds.

  • One problem, solved in five parts; six acts are the hands-on moments.
  • Two seats on every concept and act page: the security engineer’s and the developer’s.
  • Concepts arrive when the story needs them, one per page.
  • No scripts: you type every command and write every file.
  • Every number on this site was measured, and says where it came from. Anything not checked says “not checked”.

Read moreThe Strands Box repository and its READMEBox docs

Read moreHow Box works, from the box CLI’s point of viewBox docs

Read moreFurther reading, by topicThis workshop

Start with the story