View a markdown version of this page

Control access to attached storage with Strands Box - Amazon Bedrock AgentCore

Control access to attached storage with Strands Box

Strands Box runs your agent in a sandbox inside its AgentCore Runtime session. For more information about Strands Box, see Strands Box on the Strands Agents website. This topic describes how the Strands Box profile and policy files apply to storage that you attach to the Runtime. For more information about attaching storage, see File system configurations for AgentCore Runtime.

For instructions on adding attached storage to a Strands Box project, see Give the agent access to attached storage.

How the Strands Box profile controls access to attached storage

Strands Box treats attached storage differently from the other folders that the agent can reach. The following table compares the two.

Access control for a project folder and an attached storage path
What you want A folder in your project An attached storage path

Let the agent read, write, or run files

Add the folder to the read, write, or exec list.

Add the path to the read, write, and exec lists, and to receive_mounts. Strands Box requires all three grants on the whole path.

Make part of the folder read-only, or keep the agent out of it

Grant a narrower path, or use deny or deny_write.

Not available in Strands Box. Set the limit on the storage.

Stop the agent from running programs in the folder

Leave the folder out of the exec list.

Not available in Strands Box. Set the limit on the storage.

Strands Box does not start if a required grant is missing. It also does not start if a deny or deny_write entry covers the attached storage path.

The rest of the Strands Box profile works as before. Strands Box still checks each network request that the agent makes. It still limits the agent’s access to every path outside the attached storage.

Set access limits on the storage

Inside an attached storage path, Strands Box does not restrict what the agent reads, writes, or runs. To limit access, use the access controls of the storage. For example, scope the Amazon Elastic File System (Amazon EFS) access point. You can also scope the AWS Identity and Access Management (IAM) permissions that the Runtime uses for the storage.

For more information about the profile settings for attached storage, see Incoming storage mounts on Linux on the Strands Agents website.

Control shell commands on attached storage

Your agent, or one of its tools, can read the same file on attached storage in two ways. When the tool opens the file directly, the storage permissions determine whether it can read or write that file. When the tool asks Strands Shell to read the file with cat, the storage permissions still apply. Strands Shell also checks the command and the file read against your policy.

The following table shows the same file read both ways. For more information about which file rules apply to each kind of access, see Where file rules apply on the Strands Agents website.

How a tool reads a file on attached storage
How the tool reads the file Example Does Strands Box policy apply?

The tool opens the file directly

open("/mnt/data/input.txt").read()

No. Only the storage permissions apply.

The tool asks Strands Shell to read the file

subprocess.run(["sh", "-c", "cat /mnt/data/input.txt"])

Yes. The storage permissions still apply. In Strands Box, sh, bash, zsh, python3, and python run in Strands Shell. Your policy decides each command and each file that the command touches.

You can’t run a shell command on attached storage until a policy rule permits it. Selecting the mount path in the profile does not allow shell commands on the storage.

A permit rule allows an operation. A forbid rule refuses an operation and always wins over a permit rule.

To write policy rules for shell commands on attached storage, complete the following steps:

  1. Create the file .box/agent/local/policy.dw beside the profile. The following policy example has three permit rules. The first rule allows the commands. The other two rules allow the commands to read and write files in /mnt/data. Replace /mnt/data with your mount path.

    @id("shell_commands") permit (principal, action == Box::Action::"shell:exec", resource) when { ["cat", "ls", "echo"].contains(context.input.program) }; @id("storage_read") permit (principal, action == Box::Action::"fs:read", resource) when { context.input.path == "/mnt/data" || context.input.path like "/mnt/data/*" }; @id("storage_write") permit (principal, action == Box::Action::"fs:write", resource) when { context.input.path like "/mnt/data/*" };
  2. Add a forbid rule to the same file to stop shell commands from writing files in one folder. The following policy example stops shell commands from writing files in /mnt/data/reports.

    @id("reports_no_write") forbid (principal, action == Box::Action::"fs:write", resource) when { context.input.path like "/mnt/data/reports/*" };
  3. Add the policy file to the policies list at the top of .box/agent/local/profile.toml. The following TOML example shows the list.

    policies = ["aws-metadata-block.dw", "policy.dw"]
  4. Build and deploy the project again with the following commands. The build checks the rules and stops if a rule is not valid.

    agentcore build agentcore deploy

The following table shows what each command does with each set of rules.

Results for each command with each set of rules
What the agent runs With no rules With the three permit rules With the forbid rule added

sh -c "cat /mnt/data/input.txt"

Refused

Works

Works

sh -c "echo done > /mnt/data/status.txt"

Refused

Works

Works

sh -c "echo done > /mnt/data/reports/status.txt"

Refused

Works

Refused

open("/mnt/data/reports/status.txt", "w") in the agent’s own code

Works

Works

Works

When Strands Box refuses a command, the command fails with a message that names the rule. The following example shows the message with no rules.

strands-shell: cat: effect denied: policy denied this operation on 'cat' [default-deny]: No permit policy matched this request.

The following example shows the message when the forbid rule refuses a write to the reports folder.

strands-shell: /mnt/data/reports/status.txt: policy denied this operation on '/mnt/data/reports/status.txt' [policy: reports_no_write].
A forbid rule does not protect data

A forbid rule does not protect data on attached storage. As the last row of the table shows, the agent’s own code can still write to a folder that a forbid rule covers. To keep the agent from reading or changing data, set the limit on the storage.

To let the agent run Python through Strands Box on the storage, add "python3" to the list of commands in the first rule.

For more information about rules for shell commands, see Write policy for shell commands on the Strands Agents website.