Get started with Strands Box on AgentCore Runtime
Strands Box is in preview. Features and commands might change before general availability.
Strands Box (Box) runs your agent in a sandbox inside its AgentCore Runtime session. Box checks each network request that the agent makes against a policy before the request leaves. The policy denies every request that you do not allow. The AgentCore CLI creates the Box profile that holds the policy. It also creates the Runtime and a Box gateway. The gateway carries the agent’s calls to Amazon Bedrock and to the hosts that you allow. You do not write any infrastructure code.
This page provides a concise workflow for creating, testing, and deploying a Strands agent that runs in Box on AgentCore Runtime. For more information about Box, see Strands Box
In this tutorial, you do these tasks:
-
Create a Box project with the AgentCore CLI.
-
Run the agent locally to see Box block a request.
-
Allow one host in the Box profile.
-
Deploy the project.
-
Read the Box decisions in the Runtime logs.
-
Clean up the resources.
This tutorial uses the default containment, contained. You do not need a virtual private cloud (VPC) to try the policy. To add one, see Run the Runtime in a private VPC.
The AWS resources that you create in this tutorial might result in charges to your AWS account. These resources include the Runtime, the AWS CodeBuild image builds, the AgentCore Memory resource, and the Box gateway. They also include Amazon CloudWatch Logs and the Amazon Bedrock model calls. For more information about pricing, see AgentCore pricing
Prerequisites
-
Install the AgentCore CLI as described in Install the AgentCore CLI.
-
Configure your AWS credentials and permissions as described in Prerequisites.
-
Strands Box. The AgentCore CLI uses the
boxprogram to read your Box profile when it builds and deploys. Install it as described in Install Boxon the Strands Agents website, and then check it with box --version. Use an Apple silicon Mac or a Linux ARM64 machine. The Box installer turns on usage telemetry by default. To opt out, runbox telemetry off. -
A container engine. Install Docker, Podman, or Finch to test the project locally with
agentcore dev. The deployed image builds in AWS CodeBuild, so you do not need an engine to deploy. -
A supported AWS Region. Box projects run on Runtime platform version V2. Before you create the project, choose a Region that supports V2. For the list, see Supported Regions.
Create your agent project
Create a Python project that uses the Strands Agents SDK and Amazon Bedrock, and that runs in Box:
agentcore create \ --name MyBoxProject \ --template agent-python-strands-box-container
Change to the project folder. Run the other commands on this page from this folder:
cd MyBoxProject
The template creates a Python container Runtime named agent on platform version V2. It adds an AgentCore Memory resource and a Box gateway named agent-box-egress. It also installs the project dependencies. The CLI also writes the Box profile in .box/agent/local/profile.toml, and the policy file aws-metadata-block.dw beside it. The profile lists the policy files that Box loads, the command that starts the agent, and the egress that the agent is allowed. The policy file keeps the agent from the instance metadata service.
When you deploy, the CLI creates these resources in your AWS account. For the list, see Resources that the CLI creates.
The CLI warns about two things. The Runtime log group stays after you remove the Runtime. The Box gateway keeps its application logs for 90 days. Those logs can hold the request and response bodies of the gateway’s calls. To stop the gateway logs, set "enableApplicationLogs": false on the gateway in agentcore/agentcore.json.
Test your agent locally
The template agent has one tool, add_numbers. To see Box work, add a tool that calls one of two fixed web hosts. In app/agent/main.py, add this tool after the line tools.append(add_numbers):
SITES = { "github": "https://api.github.com/zen", "example": "https://example.com", } @tool def fetch_site(site: str) -> str: """Fetch the first 500 characters from a known site. The site is "github" or "example".""" import urllib.request url = SITES.get(site) if url is None: return f"UNKNOWN SITE: {site}" try: with urllib.request.urlopen(url, timeout=10) as r: return r.read(500).decode("utf-8", "replace") except Exception as e: return f"FETCH FAILED: {type(e).__name__}: {e}" tools.append(fetch_site)
Start the Runtime locally. Run this command in one terminal, and leave it running:
agentcore dev
The command builds the container image and starts the agent in Box on your machine. When the output shows Application startup complete, call the agent from a second terminal in the project folder:
agentcore invoke --local --runtime agent \ --payload '{"prompt":"Use the fetch_site tool with the site github and tell me exactly what it returned."}'
The agent reports that the fetch failed with Tunnel connection failed: 403 Forbidden. Box denied the request because no rule in the profile allows api.github.com.
Allow one more host
You declare the hosts that your agent can reach in the Box profile, and nowhere else. Stop agentcore dev with Ctrl+C. Then add this entry to the end of .box/agent/local/profile.toml:
[egress.github] destinations = ["api.github.com"]
Start agentcore dev again, and run the same agentcore invoke --local command. This time the agent returns the line that https://api.github.com/zen sends.
When you build the project, the CLI turns each allowed host into a target on the project’s Box gateway. For this entry, agentcore build prints adding gateway target 'egress-github' to 'agent-box-egress' for api.github.com. You do not edit the gateway. To allow or remove a host, change the profile and build again.
The example host needs no credential. For a host that needs one, give its entry a secret.ref. Use aws:// for an AWS service that signs with SigV4, or env:// for an API key in an environment variable. For more information about profiles, see Profiles
Build and deploy your agent
agentcore build agentcore deploy
The first deployment takes several minutes while AWS CodeBuild builds the container image. Check the deployed resources:
agentcore status
The status lists the deployed Runtime, the Memory resource, and the Box gateway with its targets. The bedrock target is for the model calls. The egress-github target is for the host that you allowed.
Invoke your deployed agent
Ask the agent to call one host that the profile allows and one that it does not:
agentcore invoke --runtime agent \ --payload '{"prompt":"Use fetch_site with the site github and tell me what it returned. Then use fetch_site with the site example and tell me what happened."}'
The first call returns a line from GitHub. The second fails with Tunnel connection failed: 403 Forbidden, because the profile does not allow example.com.
See what Box blocked
On Amazon Bedrock AgentCore Runtime, Box writes each policy decision to the Runtime’s log group. To list the denied requests, search the Runtime logs for deny:
agentcore logs runtime --since 15m --query '"deny"'
Each record is one decision. The following table lists the fields that describe the request that Box denied.
| Field | Example value |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The <default-deny> rule and the no_match cause mean that no rule in the policy permitted the request.
Run the Runtime in a private VPC
The agentcore create command takes a --containment option with two values. The following table describes the values.
| Value | What the agent can reach | What the CLI adds |
|---|---|---|
|
|
Only the hosts that its Box profile allows. Box checks each outbound request against the policy. Calls to Amazon Bedrock and to the hosts that you allow leave through the agent’s own Box gateway. Calls to AgentCore Memory go directly to AgentCore, and Box checks them against the policy too. |
The Box profile, and one Box gateway for each Runtime. |
|
|
The same hosts as |
Everything in |
The steps on this page use the default, contained. To also run the Runtime in a private VPC, add --containment private-vpc when you create the project:
agentcore create \ --name MyBoxProject \ --template agent-python-strands-box-container \ --containment private-vpc
The CLI prints the estimated cost of the VPC when it creates the project. For example, if you deploy a container Runtime, the estimate might be about USD $88 per month while the VPC is deployed. The estimate is higher with three Availability Zones. The VPC stays after you delete the stack, and it counts toward your account’s VPC quota until you delete it.
For the resources that each value creates, see Resources that the CLI creates.
Give the agent access to attached storage
This step is optional. With AgentCore Runtime, you can attach storage to a session. For more information, see File system configurations for AgentCore Runtime.
The CLI does not add attached storage to the Strands Box profile. Storage might already be mounted when Strands Box starts, or Runtime might attach it later. To receive storage that is mounted later, the profile must select the mount path before Strands Box starts. In both cases, the profile must grant the agent access to the path. If the profile does not include the mount path, the project still deploys, but the agent cannot use the storage.
To give the agent access to attached storage, complete the following steps:
-
Add the file system configuration to the Runtime in
agentcore/agentcore.json. The following JSON example adds managed session storage. Replace/mnt/datawith your mount path."filesystemConfigurations": [ { "sessionStorage": { "mountPath": "/mnt/data" } } ] -
Add the mount path to the
[agent.filesystem]table in.box/agent/local/profile.toml. Add the path to theread,write, andexeclists to grant access. Add the path toreceive_mountsto select it for storage that is mounted later. Keep the entries that the CLI wrote. The following TOML example shows the table for the project in this tutorial.[agent.filesystem] read = ["${{ workspace }}", "/usr/local/lib", "/usr/lib/aarch64-linux-gnu", "/mnt/data"] write = ["/mnt/data"] exec = [{ path = "${{ workspace }}/.venv", optional = true }, "/usr/local/bin", "/usr/local/lib", "/usr/lib/aarch64-linux-gnu", "/mnt/data"] deny_write = [{ path = "${{ workspace }}/.venv", optional = true }] receive_mounts = ["/mnt/data"] -
Build and deploy the project again with the following commands.
agentcore build agentcore deploy
To avoid ongoing charges for the attached storage, remove the storage and the other project resources when you finish. For instructions on removing the resources, see Clean up.
With these entries in the profile, agentcore dev does not start if no storage is mounted at the path. Add the entries when you are ready to deploy.
Strands Box does not restrict what the agent reads, writes, or runs inside attached storage. Policy rules in the Strands Box profile do not apply to the agent’s own file access there. To limit access, use the access controls of the storage.
For more information about how the Strands Box profile and policy rules apply to attached storage, see Control access to attached storage with Strands Box.
Clean up
These steps permanently delete the resources of the project. Make sure that you no longer need them before you continue.
To delete the project resources
-
Record the identifiers of this deployment before you delete it. The stack outputs are deleted with the stack. The following commands use the stack name of this tutorial.
agentcore deployprinted the name when it deployed, on a line such asdeploying AgentCore-MyBoxProject-default. Replace it with the name of your stack. Replaceregionwith the AWS Region of the deploy target.aws cloudformation describe-stacks --regionregion--stack-name AgentCore-MyBoxProject-default \ --query 'Stacks[0].StackId' --output text aws cloudformation describe-stacks --regionregion--stack-name AgentCore-MyBoxProject-default \ --query "Stacks[0].Outputs[?ExportName=='AgentCore-MyBoxProject-default-agent-RuntimeId'].OutputValue" --output text aws cloudformation describe-stack-resources --regionregion--stack-name AgentCore-MyBoxProject-default \ --query "StackResources[?ResourceType=='AWS::CodeBuild::Project'].PhysicalResourceId" --output textThe commands print the stack ID, the Runtime ID, and the name of the CodeBuild project. Keep the three values for the later steps.
-
Remove the resources of the project from the project specification.
agentcore remove all --yes -
Deploy to delete the Runtime, the gateway, the memory, and the stack. You can watch the delete on the Events tab of the stack in the CloudFormation console.
agentcore deploy --yes
The deploy deletes the stack, but CloudFormation keeps some of the resources in it. To list the resources that it kept, use the stack ID that you recorded. Do not look the stack up by its name, because a name can match more than one deleted stack. Replace stack-id with the stack ID:
aws cloudformation list-stack-resources --regionregion--stack-namestack-id\ --query "StackResourceSummaries[?ResourceStatus=='DELETE_SKIPPED'].[ResourceType,PhysicalResourceId]" --output text
For the project in this tutorial, the list has one resource: the log group of the Lambda function that starts the image build. Delete each resource that you no longer need. For a log group, use this command:
aws logs delete-log-group --regionregion--log-group-namelog-group-name
The log groups of the Runtime and of the CodeBuild project are not part of the stack, so the list does not show them. Their names contain the Runtime ID and the CodeBuild project name that you recorded. Replace runtime-id and codebuild-project-name with those values:
aws logs delete-log-group --regionregion--log-group-name /aws/bedrock-agentcore/runtimes/runtime-id-DEFAULT aws logs delete-log-group --regionregion--log-group-name /aws/codebuild/codebuild-project-name
Delete these log groups by their full names. Do not delete log groups by a name prefix. A prefix that has only the project name also matches the log groups of the other deploy targets of the project.
The deploy also leaves the AWS KMS key of the Amazon Elastic Container Registry (Amazon ECR) repository in the Pending deletion state. AWS KMS deletes it after 30 days.
If you created the project with --containment private-vpc, the list also has the network resources. These are the VPC, its two subnets, and two security groups. They also include a route table that is not the main route table. The list also has the log groups for the DNS query logs and the VPC flow logs. The VPC counts toward your account’s VPC quota until you delete it.
To delete the VPC, delete the subnets, the security groups, and the route table first. If the VPC still has network interfaces, wait until AgentCore releases them. Then delete the VPC:
aws ec2 delete-subnet --regionregion--subnet-idsubnet-idaws ec2 delete-security-group --regionregion--group-idsecurity-group-idaws ec2 delete-route-table --regionregion--route-table-idroute-table-idaws ec2 delete-vpc --regionregion--vpc-idvpc-id
Troubleshoot
For common CLI installation, deployment, configuration, and observability issues, see Troubleshoot. For Box errors, see Troubleshooting
Resources that the CLI creates
When you deploy, the CLI creates the resources of your project in your AWS account. They are in one AWS CloudFormation stack. You declare the resources in agentcore/agentcore.json and in the Box profile. You do not write infrastructure code.
The stack name is AgentCore-
project-name-target-name, as described in Use the AgentCore CLI. agentcore deploy prints the name. For the project in this tutorial, the name is AgentCore-MyBoxProject-default.
With the default, contained
The following table lists the resources in the stack.
| Resource | What it does |
|---|---|
|
AgentCore Runtime |
Runs your agent in Box. The Runtime uses a container image and platform version V2. |
|
AgentCore Memory |
Stores the memory of the agent. The template adds it. The Runtime calls it directly, not through the gateway. |
|
AgentCore Gateway |
Carries the agent’s calls to Amazon Bedrock and to the hosts that you allow. It has one target for Amazon Bedrock, and one |
|
Container image build |
An Amazon ECR repository, encrypted with an AWS KMS key, an AWS CodeBuild project, and a Lambda function that starts the build. |
|
IAM roles and policies |
The roles for the Runtime, the gateway, Memory, and the image build. |
|
Amazon CloudWatch Logs |
A log group and a log delivery for the gateway’s application logs. The Runtime also has its own log group, which AgentCore creates outside the stack. |
The first deploy in an account and Region also does two things outside the stack. It bootstraps AWS CDK, if needed, and it turns on CloudWatch Transaction Search. To skip Transaction Search, run agentcore config transactionSearch false.
With private-vpc
The stack has everything in the previous table. The following table lists the additional resources.
| Resource | What it does |
|---|---|
|
VPC |
A VPC with two private subnets and a route table. It has no internet gateway and no NAT gateway. |
|
Security groups |
One for the Runtime and one for the VPC endpoints. |
|
VPC endpoints |
An Amazon S3 gateway endpoint. Interface endpoints for the AgentCore gateway, the AgentCore data plane, CloudWatch Logs, CloudWatch metrics, AWS X-Ray, and Amazon ECR (API and Docker). |
|
Route 53 DNS Firewall |
A rule group with a list of domain names to allow and a list to block, and query logs in CloudWatch Logs. |
|
VPC flow logs |
Records of the network traffic in the VPC. |
|
Supporting resources |
More IAM roles, Lambda functions, and log groups that set up the network. |
To see what the CLI created, run agentcore status, or open the stack in the CloudFormation console. In the console, choose the stack. The Resources tab lists the resources. The Events tab shows what happened during a deploy or a delete. agentcore status lists only the resources that you declare in agentcore.json, so the stack is the complete list.
To change a resource, change the project file or the Box profile, and deploy again. A later deploy can overwrite changes that you make directly to these resources. To delete them, see Clean up.
Next steps
-
Get started with Amazon Bedrock AgentCore - use the complete AgentCore CLI workflow.
-
Security best practices for AgentCore Runtime - review the controls that apply to every Runtime.
-
Control access to attached storage with Strands Box - learn how the Strands Box profile and policy rules apply to attached storage.
-
How Box works
on the Strands Agents website - read how Box checks requests against your policy. -
Limitations
on the Strands Agents website - read what a box does not protect you from. -
Run a Box shipment agent on AgentCore Runtime
on the Strands Agents website - deploy a Box sample to Runtime without the AgentCore CLI.