

# Get started with Strands Box on AgentCore Runtime

**Note**  
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](https://strandsagents.com/docs/user-guide/box/) on the Strands Agents website. For CLI installation, complete prerequisites, project capabilities, observability, and cleanup, see [Get started with Amazon Bedrock AgentCore](agentcore-get-started-cli.md).

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](#runtime-get-started-box-containment).

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](https://aws.amazon.com/bedrock/agentcore/pricing/) on the AWS website. To stop the charges, remove the resources in [Clean up](#runtime-get-started-box-clean-up). For the list of resources that the CLI creates, see [Resources that the CLI creates](#runtime-get-started-box-resources).

## Prerequisites
<a name="runtime-get-started-box-prerequisites"></a>
+ Install the AgentCore CLI as described in [Install the AgentCore CLI](agentcore-get-started-cli.md#agentcore-get-started-cli-install).
+ Configure your AWS credentials and permissions as described in [Prerequisites](agentcore-get-started-cli.md#agentcore-get-started-cli-prerequisites).
+  **Strands Box.** The AgentCore CLI uses the `box` program to read your Box profile when it builds and deploys. Install it as described in [Install Box](https://strandsagents.com/docs/user-guide/box/install/) on 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, run `box 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](runtime-how-it-works.md#runtime-platform-versions-regions).

## Create your agent project
<a name="runtime-get-started-box-create"></a>

Create a Python project that uses the Strands Agents SDK and Amazon Bedrock, and that runs in Box:

```bash
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:

```bash
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.

**Note**  
When you deploy, the CLI creates these resources in your AWS account. For the list, see [Resources that the CLI creates](#runtime-get-started-box-resources).

**Note**  
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
<a name="runtime-get-started-box-test"></a>

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)`:

```python
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:

```bash
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:

```bash
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
<a name="runtime-get-started-box-allow"></a>

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

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

**Note**  
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](https://strandsagents.com/docs/user-guide/box/profiles/) in the Strands Box documentation on the Strands Agents website.

## Build and deploy your agent
<a name="runtime-get-started-box-deploy"></a>

```bash
agentcore build
agentcore deploy
```

The first deployment takes several minutes while AWS CodeBuild builds the container image. Check the deployed resources:

```bash
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
<a name="runtime-get-started-box-invoke"></a>

Ask the agent to call one host that the profile allows and one that it does not:

```bash
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
<a name="runtime-get-started-box-logs"></a>

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

```bash
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 | 
| --- | --- | 
|  `strands.box.policy.action`  |  `net:connect`  | 
|  `strands.box.policy.resource`  |  `example.com:443`  | 
|  `strands.box.policy.verdict`  |  `deny`  | 
|  `strands.box.policy.rule`  |  `<default-deny>`  | 
|  `strands.box.policy.cause`  |  `no_match`  | 

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
<a name="runtime-get-started-box-containment"></a>

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 | 
| --- | --- | --- | 
|  `contained` (default) | 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. | 
|  `private-vpc`  | The same hosts as `contained`. The Runtime also runs in a private VPC that has no internet path. | Everything in `contained`, plus a VPC for each Runtime. | 

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:

```bash
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](#runtime-get-started-box-resources).

## Give the agent access to attached storage
<a name="runtime-get-started-box-storage"></a>

This step is optional. With AgentCore Runtime, you can attach storage to a session. For more information, see [File system configurations for AgentCore Runtime](runtime-filesystem-configurations.md).

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:

1. Add the file system configuration to the Runtime in `agentcore/agentcore.json`. The following JSON example adds managed session storage. Replace `/mnt/data` with your mount path.

   ```json
   "filesystemConfigurations": [
     { "sessionStorage": { "mountPath": "/mnt/data" } }
   ]
   ```

1. Add the mount path to the `[agent.filesystem]` table in `.box/agent/local/profile.toml`. Add the path to the `read`, `write`, and `exec` lists to grant access. Add the path to `receive_mounts` to 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.

   ```toml
   [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"]
   ```

1. Build and deploy the project again with the following commands.

   ```bash
   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](#runtime-get-started-box-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.

**Set access limits on the storage**  
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](runtime-box-storage.md).

## Clean up
<a name="runtime-get-started-box-clean-up"></a>

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

1. 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 deploy` printed the name when it deployed, on a line such as `deploying AgentCore-MyBoxProject-default`. Replace it with the name of your stack. Replace {{region}} with the AWS Region of the deploy target.

   ```bash
   aws cloudformation describe-stacks --region {{region}} --stack-name AgentCore-MyBoxProject-default \
     --query 'Stacks[0].StackId' --output text
   aws cloudformation describe-stacks --region {{region}} --stack-name AgentCore-MyBoxProject-default \
     --query "Stacks[0].Outputs[?ExportName=='AgentCore-MyBoxProject-default-agent-RuntimeId'].OutputValue" --output text
   aws cloudformation describe-stack-resources --region {{region}} --stack-name AgentCore-MyBoxProject-default \
     --query "StackResources[?ResourceType=='AWS::CodeBuild::Project'].PhysicalResourceId" --output text
   ```

   The commands print the stack ID, the Runtime ID, and the name of the CodeBuild project. Keep the three values for the later steps.

1. Remove the resources of the project from the project specification.

   ```bash
   agentcore remove all --yes
   ```

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

   ```bash
   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:

```bash
aws cloudformation list-stack-resources --region {{region}} --stack-name {{stack-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:

```bash
aws logs delete-log-group --region {{region}} --log-group-name {{log-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:

```bash
aws logs delete-log-group --region {{region}} --log-group-name /aws/bedrock-agentcore/runtimes/{{runtime-id}}-DEFAULT
aws logs delete-log-group --region {{region}} --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:

```bash
aws ec2 delete-subnet --region {{region}} --subnet-id {{subnet-id}}
aws ec2 delete-security-group --region {{region}} --group-id {{security-group-id}}
aws ec2 delete-route-table --region {{region}} --route-table-id {{route-table-id}}
aws ec2 delete-vpc --region {{region}} --vpc-id {{vpc-id}}
```

## Troubleshoot
<a name="runtime-get-started-box-common-issues"></a>

For common CLI installation, deployment, configuration, and observability issues, see [Troubleshoot](agentcore-get-started-cli.md#agentcore-get-started-cli-troubleshoot). For Box errors, see [Troubleshooting](https://strandsagents.com/docs/user-guide/box/troubleshooting/) in the Strands Box documentation on the Strands Agents website.

## Resources that the CLI creates
<a name="runtime-get-started-box-resources"></a>

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](runtime-permissions.md#runtime-permissions-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 `agent-box-egress`  | Carries the agent’s calls to Amazon Bedrock and to the hosts that you allow. It has one target for Amazon Bedrock, and one `egress-` target for each host that you allow. A resource policy lets only the execution role of the Runtime call it. | 
| 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](#runtime-get-started-box-clean-up).

## Next steps
<a name="runtime-get-started-box-next-steps"></a>
+  [Get started with Amazon Bedrock AgentCore](agentcore-get-started-cli.md) - use the complete AgentCore CLI workflow.
+  [Security best practices for AgentCore Runtime](runtime-security-best-practices.md) - review the controls that apply to every Runtime.
+  [Control access to attached storage with Strands Box](runtime-box-storage.md) - learn how the Strands Box profile and policy rules apply to attached storage.
+  [How Box works](https://strandsagents.com/docs/user-guide/box/how-box-works/) on the Strands Agents website - read how Box checks requests against your policy.
+  [Limitations](https://strandsagents.com/docs/user-guide/box/limitations/) on the Strands Agents website - read what a box does not protect you from.
+  [Run a Box shipment agent on AgentCore Runtime](https://strandsagents.com/docs/user-guide/box/guides/deploy-to-agentcore-runtime/) on the Strands Agents website - deploy a Box sample to Runtime without the AgentCore CLI.