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

One-time set-up

This page prepares the one terminal you keep open for the whole workshop: the box build on your PATH, the three secrets in the macOS keychain and in shell variables, a Box home of its own, telemetry off, and the workspace folder with its first file. After it you will know where each secret lives at every moment, and why the folders are where they are. Part 1 starts from exactly this state.

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

This page fills the keychain and the developer's terminal. The secrets go from the keychain into the terminal's variables, never onto a command line or into a file.

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

Nothing is new in the picture. This page works on two of its pieces: the macOS keychain (top left) and the developer’s terminal beside it.

Open a new terminal window. The set-up below was proven in a fresh shell with nothing inherited. Two variables in particular would change every run if your shell already sets them: ANTHROPIC_BASE_URL changes where Claude Code sends its model calls, and ANTHROPIC_MODEL changes which model it uses.

What this doesPrints the two variables if they are set; prints nothing if they are not.

Terminal window
printenv ANTHROPIC_BASE_URL ANTHROPIC_MODEL
ANTHROPIC_BASE_URL ANTHROPIC_MODEL
The names of the variables to print. printenv prints the value of each one that is set.
What you should see
Nothing is printed. If a line appears, open a terminal where your shell’s start-up files do not set it, or remove it for this terminal with unset and the variable’s name.

Iteration 1 below puts the folder $HOME/box-build on your PATH, so the build must be there first. You need the commands in this section only if you do not already have the workshop’s build in that folder.

The build commands, one at a time

Work in an empty folder in your home (not under /tmp). You need git, mise (for the Rust toolchain) and a network connection for Rust’s packages.

  1. What this doesDownloads the Box source with the fix, from the fork's workshop branch.

    Terminal window
    git clone --branch bugfix/mcp-shared-definitions-workshop https://github.com/so0k/box.git box-src
    --branch bugfix/mcp-shared-definitions-workshop
    Checks out this branch after the download: upstream commit c70fec5 plus the fix.
    https://github.com/so0k/box.git
    The fork of strands-agents/box that holds the fix.
    box-src
    The folder to clone into.
  2. What this doesMoves into the downloaded source folder. Every command below runs from here.

    Terminal window
    cd box-src
    box-src
    The folder git clone just made.
  3. What this doesBuilds the box CLI and its two helper programs with a pinned Rust toolchain.

    Terminal window
    MACOSX_DEPLOYMENT_TARGET=15.0 CARGO_HTTP_TIMEOUT=300 mise x rust@1.98.1 -- \
    cargo build --release --locked -p strands-box-cli -p strands-box -p strands-box-containment \
    --bin box --bin strands-box --bin strands-box-sock-alias --bin strands-box-contain-trampoline
    MACOSX_DEPLOYMENT_TARGET=15.0
    The oldest macOS the binaries are built for, as the build record says.
    CARGO_HTTP_TIMEOUT=300
    Gives slow package downloads up to 300 seconds.
    mise x rust@1.98.1 --
    Runs the build with Rust 1.98.1, the version the build record names. Whether another version builds the same was not checked.
    --release
    An optimised build.
    --locked
    Refuses to change Cargo.lock, so the dependencies are exactly the source’s.
    -p ... --bin ...
    The packages and programs to build. strands-box (Box Core’s own command) is built too, but the workshop does not use it.
  4. What this doesMakes the folder the workshop uses for the build.

    Terminal window
    mkdir -p "$HOME/box-build/resources"
    -p
    Makes box-build and resources inside it in one step, and gives no error if they already exist.
    "$HOME/box-build/resources"
    The build folder, with the resources folder the shipped files go into below.
  5. What this doesCopies the box binary and its two helpers into the build folder.

    Terminal window
    cp target/release/box target/release/strands-box-sock-alias target/release/strands-box-contain-trampoline "$HOME/box-build/"
    strands-box-sock-alias, strands-box-contain-trampoline
    The two helpers must sit beside box. The trampoline applies the macOS sandbox and then becomes the program it starts.
  6. What this doesCopies the shipped packs, starters, policy starters and the agent guide beside the binary.

    Terminal window
    cp -R resources/config.toml resources/editing-box-profile.md resources/packs resources/plugins resources/policies resources/starters "$HOME/box-build/resources/"
    -R
    Copies folders with everything in them.
    $HOME/box-build/resources/
    The CLI looks for its shipped files in a resources/ folder beside the binary, the way a release package lays them out.
  7. What this doesRuns the new binary and prints its version. It changes nothing.

    Terminal window
    "$HOME/box-build/box" --version
    --version
    Prints the version and exits.

    It should print box 0.1.0.

Read moreBuilds and gaps: what this build is, and what a released Box still lacksThis workshop

Iteration 1Put the workshop's box build first on the PATH

What we add. The folder of the local box build, in front of every other folder the shell searches for commands.

The run.

What this doesPuts the workshop's box build in front of everything else on the PATH, for this terminal.

Terminal window
export PATH="$HOME/box-build:$PATH"
export
Makes the variable visible to every program started from this terminal, not only to the shell itself.
$HOME/box-build
The folder that holds the build’s box binary and its helpers (requirements).
:$PATH
Keeps the folders that were already on the PATH, after the new one.

What we see. Nothing: an export prints nothing. Two checks show which box now answers.

What this doesPrints the path of the box command the shell finds.

Terminal window
command -v box
-v
Prints the path the shell would run, without running it.
What you should see
<your-home>/box-build/box

What this doesPrints the version of the box that answers.

Terminal window
box --version
--version
Prints the version and exits.
What you should see
box 0.1.0
Iteration 2Store the three secrets in the keychain, once

What we add. Three items in your login keychain, all under the account name box-exec-proxy-poc, one service name per secret:

Service name The secret
anthropic-api-key Your Anthropic API key
box-poc-mcp-token The Cloudflare MCP token (with User Details Read)
box-poc-agent-token The Cloudflare agent token

You do this once per machine, not once per terminal.

The run. One command per secret. Each one asks you for the value; paste it at the prompt.

What this doesAdds the Anthropic API key to the login keychain, asking for the value instead of taking it on the command line.

Terminal window
security add-generic-password -a box-exec-proxy-poc -s anthropic-api-key -w
add-generic-password
Adds a password item to the default keychain, which is your login keychain.
-a box-exec-proxy-poc
The account name. All three items share it, so the later commands find them by the pair of account and service.
-s anthropic-api-key
The service name: which secret this is.
-w
The value. Put last with nothing after it, security asks for the value instead of reading it from the command line. That is what keeps the secret out of your shell history and out of the process list.
Terminal window
security add-generic-password -a box-exec-proxy-poc -s box-poc-mcp-token -w
Terminal window
security add-generic-password -a box-exec-proxy-poc -s box-poc-agent-token -w

The two Cloudflare commands differ only in the service name. If an item already exists, security refuses to add it again; add -U before -w to update it instead.

Their form is from man security, which says of -w: “Put at end of command to be prompted (recommended)”. What exactly the prompt looks like, and whether it hides what you paste, was not checked.

What we see. A check that each item exists, without printing its value:

What this doesShows the keychain item's attributes; without -w it does not print the secret.

Terminal window
security find-generic-password -s anthropic-api-key -a box-exec-proxy-poc
find-generic-password
Looks up one password item.
-s anthropic-api-key
The service name to look for.
-a box-exec-proxy-poc
The account name to look for.
What you should see (abridged)
keychain: "<your-home>/Library/Keychains/login.keychain-db"
class: "genp"
attributes:
"acct"<blob>="box-exec-proxy-poc"
"svce"<blob>="anthropic-api-key"

A missing item prints security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain. instead. Repeat the check with the two other service names.

Iteration 3Read the secrets into shell variables

What we add. Three variables in this terminal, each read from its keychain item. You repeat this in every new terminal.

The run.

What this doesReads the Anthropic API key from the keychain into a variable, without showing it.

Terminal window
export ANTHROPIC_API_KEY="$(security find-generic-password -s anthropic-api-key -a box-exec-proxy-poc -w)"
ANTHROPIC_API_KEY
The variable Claude Code reads its API key from. In the box acts the profile also names it, so Box knows which value to keep for itself.
$( ... )
Runs the command inside and puts what it prints into the variable, so the value never appears on the screen.
-w
On find-generic-password, prints only the secret’s value. Here it goes into the variable, not to the screen.

What this doesReads the Cloudflare MCP token into a variable.

Terminal window
export CLOUDFLARE_MCP_TOKEN="$(security find-generic-password -s box-poc-mcp-token -a box-exec-proxy-poc -w)"
CLOUDFLARE_MCP_TOKEN
The token for Cloudflare’s MCP server. Claude Code fills it into the server’s Authorization header from the MCP config file you write in step 7.

What this doesReads the Cloudflare agent token into a variable.

Terminal window
export CLOUDFLARE_API_TOKEN="$(security find-generic-password -s box-poc-agent-token -a box-exec-proxy-poc -w)"
CLOUDFLARE_API_TOKEN
The token for direct calls to the Cloudflare API, which Box adds to each permitted request in act c.

What we see. Nothing on the screen. A check that a variable holds something, without printing it:

What this doesPrints set if the variable is not empty, and nothing otherwise.

Terminal window
[ -n "$ANTHROPIC_API_KEY" ] && echo set
[ -n ... ]
A test that is true when the text is not empty.
&& echo set
Prints set only if the test was true. The value itself is never printed.
What you should see
set

Repeat it with CLOUDFLARE_MCP_TOKEN and CLOUDFLARE_API_TOKEN.

Iteration 4Give Box a home of its own, with a short path

What we add. The Box home: the folder where the box CLI keeps profiles, the agent’s storage and the records of each run.

The run.

What this doesTells the box CLI to keep its profiles, storage and runs in a folder of its own.

Terminal window
export BOX_HOME="$HOME/box-ws"
BOX_HOME
The box CLI’s home folder. It must be a full path. Without it the CLI uses ~/.strands/box.
$HOME/box-ws
A new folder just for this workshop. ws is short for workshop; the name is short on purpose (see below).

What we see. Nothing. A check of the path’s length:

What this doesCounts the bytes in the Box home's path.

Terminal window
echo -n "$BOX_HOME" | wc -c
echo -n
Prints the path without a newline after it, so the newline is not counted.
wc -c
Counts the bytes it receives.
What you should see (on the machine this site was written on)
25

The number must be 65 or less.

Read moreWhere Box keeps its filesBox docs

Read moreTroubleshooting, including the socket path limitBox docs

Iteration 5Turn usage telemetry off for this terminal

What we add. One variable that stops the box CLI from sending usage events.

The run.

What this doesTurns the box CLI's usage telemetry off for every command in this terminal.

Terminal window
export BOX_TELEMETRY=0
BOX_TELEMETRY=0
Off for this terminal. The CLI checks BOX_TELEMETRY first, then DO_NOT_TRACK, then a saved choice; if none is set, telemetry is on.

What we see.

What this doesPrints whether telemetry is on, and what decided it.

Terminal window
box telemetry status
telemetry status
Reports the setting; it changes nothing and sends nothing.
What you should see
Telemetry is off (set by BOX_TELEMETRY).

Read moreUsage telemetry: what is collected and what is notBox docs

Iteration 6Make the workspace folder and work in it

What we add. Two folders: the Box home itself, and the workspace, the team’s operations folder in the story. The workspace holds only the MCP config files you write; the agent starts in it.

The run.

What this doesMakes the Box home and the workspace folder, if they do not exist yet.

Terminal window
mkdir -p "$BOX_HOME" "$HOME/leaderboard-ops"
-p
Makes missing parent folders too, and does nothing if the folder already exists.
$HOME/leaderboard-ops
The workspace. In the story it is where the team keeps what it uses to operate the leaderboard app.

What this doesMakes the workspace the current folder.

Terminal window
cd "$HOME/leaderboard-ops"

What we see.

What this doesPrints the current folder.

Terminal window
pwd
What you should see
<your-home>/leaderboard-ops
Iteration 7Write the MCP config file for Cloudflare's server

What we add. One file in the workspace that tells Claude Code where Cloudflare’s MCP server is and how to sign in to it. Open your editor and save this as cloudflare-code-mode.json in the workspace:

$HOME/leaderboard-ops/cloudflare-code-mode.json
{
"mcpServers": {
"cloudflare": {
"type": "http",
"url": "https://mcp.cloudflare.com/mcp",
"headers": { "Authorization": "Bearer ${CLOUDFLARE_MCP_TOKEN}" }
}
}
}
  • "cloudflare" is the name Claude Code gives the server. Its tools appear as mcp__cloudflare__<tool>, and Box uses the same name in Part 2.
  • "type": "http" says the server is remote and reached over HTTP, not started as a local program.
  • "url" is Cloudflare’s server. Without a query string it runs in code mode (Part 1).
  • "headers" adds the token to every request. ${CLOUDFLARE_MCP_TOKEN} is a placeholder: Claude Code fills it from its own environment when it connects, so the file holds no secret.

With this file saved, the two folders in your home hold this much:

  • Directorybox-ws/ the Box home, still empty
    • …
  • Directoryleaderboard-ops/ the workspace, where the agent starts
    • cloudflare-code-mode.json you edit this

The run. Nothing to run yet. Act a’s free check is the first command that reads this file.

What we see. Act a’s free check shows the server as connected, which proves both the file and the MCP token.

Read moreConnect Claude Code to tools via MCPClaude Code docs

The exports last only as long as the terminal. If you open a new one, type steps 1, 3, 4 and 5 again and cd into the workspace. Here are those lines in one place, to copy one at a time:

The lines for a new terminal
Terminal window
export PATH="$HOME/box-build:$PATH"
Terminal window
export BOX_HOME="$HOME/box-ws"
Terminal window
export BOX_TELEMETRY=0
Terminal window
export ANTHROPIC_API_KEY="$(security find-generic-password -s anthropic-api-key -a box-exec-proxy-poc -w)"
Terminal window
export CLOUDFLARE_MCP_TOKEN="$(security find-generic-password -s box-poc-mcp-token -a box-exec-proxy-poc -w)"
Terminal window
export CLOUDFLARE_API_TOKEN="$(security find-generic-password -s box-poc-agent-token -a box-exec-proxy-poc -w)"
Terminal window
cd "$HOME/leaderboard-ops"
  • The secrets live in the keychain, under account box-exec-proxy-poc, and reach the terminal only through $(security ... -w).
  • BOX_HOME="$HOME/box-ws": a home of its own, short enough for the 103-byte socket path.
  • BOX_TELEMETRY=0 turns usage telemetry off for the terminal without writing anything outside the Box home.
  • The workspace ~/leaderboard-ops is outside the Box home and not under /tmp.
  • cloudflare-code-mode.json holds a placeholder, never the token.

Read moreThe box command reference, including its environment variablesBox docs

Read moreGet started with the box CLI and Claude CodeBox docs

Read moreClaude Code settings and environment variablesClaude Code docs