Skip to content

Run an agent in a box

Strands Box lets you run an agent in a contained sandbox, where you control which files, network hosts, and commands it can reach. This page tells how to give an agent running in a box access to a Stash mount.

Stash with Strands Box. The agent and its hooks run in the box sandbox. They reach Stash only by running the stash command, and the Box policy checks each command. Other commands stop there. The Stash daemon runs outside the box, holds the credentials, and calls the sources. The daemon writes the mount point, and the box grants the agent read access to it.

  • Strands Box installed
  • A ready mount, and a running daemon. See the Quickstart
  • A current Claude Code or Codex release

This page uses the example project ~/src/checkout-service and the mount ops. The mount’s mount_point is the context directory of the project, such as /Users/me/src/checkout-service/context.

Terminal window
cd ~/src/checkout-service
stash attach ops --no-mcp

attach connects the agents that work in this project to the mount. It writes hooks that send each turn of the agent to the mount. It also writes steering that tells the agent how to search the mount and save notes.

This is a local attach, so run box run from the same directory. To run a boxed agent in another directory, attach that directory too, and let the box read the mount point in the profile’s profile.toml:

[agent.filesystem]
read = ["~/src/checkout-service/context"]

Box’s hook import does not bring in the hooks of a global attach (stash attach --global) yet, so a global attach does not work in a box.

This guide uses --no-mcp, which attaches in CLI mode. The agent and its hooks then reach Stash only through the stash command. So a single Box policy on that command governs everything the agent does with Stash, including its searches, its notes, and the turns its hooks send.

A Box profile sets which agent runs in a box, its model provider, and the tools it can use. See the Box quickstart to learn more. A pack adds a program or a setting to a profile. The @box/stash pack is a tool pack that lets the agent and its hooks run the stash CLI in the box. The Stash daemon stays on your machine, outside the box, and the tool connects to it.

Make a profile with the pack, then run it from the project. This example uses Amazon Bedrock as the model provider:

Terminal window
box profile create claude-stash --with claude,bedrock,@box/stash
box run claude-stash

For Codex, use --with codex,bedrock-mantle,@box/stash. Codex runs the project’s hooks only after you trust the project and the hooks.

By default, the box lets the agent run any stash command. You can add a policy that permits only the commands that the agent and its hooks need, on one mount. For example, the agent then can’t run stash create.

  1. Save this file as stash.dw in the profile’s directory, ~/.strands/box/profiles/claude-stash/. Replace ops with the name of your mount.

    // Let the agent and its hooks run stash only on the mount ops.
    @id("stash_only_ops")
    forbid (principal, action == Box::Action::"shell:spawn", resource)
    when {
    context.input.program == "stash" &&
    !(context.input.command like "stash search ops *" ||
    context.input.command == "stash status ops" ||
    context.input.command == "stash tool list ops" ||
    context.input.command like "stash tool list ops *" ||
    context.input.command like "stash tool call ops *" ||
    context.input.command like "stash note save ops *" ||
    context.input.command like "stash hook --name ops *")
    };
  2. Edit the profile’s file, ~/.strands/box/profiles/claude-stash/profile.toml, to add stash.dw to the policies line near its top:

    policies = ["policy.dw", "stash.dw"]

The policy permits stash search, status, tool list, tool call, note save, and the hooks, on the mount ops. The box refuses other stash commands.

  1. Ask the agent to run a search. Each page in _sources/ shows the path of its source:

    Terminal window
    stash search ops "deploy steps" --path '/agentcore-memory/team/*'
  2. After a turn, run stash status ops on your machine. The Workspaces section lists the project.

The Strands SDK in a Box sample runs a Python Strands agent in a box on AgentCore Runtime. A trusted handler serves the mount outside the box. The box policy limits the agent to stash search and the hooks on one mount.

What you seeWhat to do
box: skipped tool stash (@box/stash): stash is not on PATHMake sure that stash is installed and on your PATH
A hook fails with EPERM and posix_spawn '/bin/sh'Run stash attach ops --no-mcp again
no mount "ops" is being servedStart the daemon, then run box run again
Codex runs no hookTrust the project, then choose Trust all and continue at Hooks need review