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
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.
| 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 |
Add the path to the |
|
Make part of the folder read-only, or keep the agent out of it |
Grant a narrower path, or use |
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 |
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.
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
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
| How the tool reads the file | Example | Does Strands Box policy apply? |
|---|---|---|
|
The tool opens the file directly |
|
No. Only the storage permissions apply. |
|
The tool asks Strands Shell to read the file |
|
Yes. The storage permissions still apply. In Strands Box, |
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:
-
Create the file
.box/agent/local/policy.dwbeside the profile. The following policy example has threepermitrules. The first rule allows the commands. The other two rules allow the commands to read and write files in/mnt/data. Replace/mnt/datawith 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/*" }; -
Add a
forbidrule 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/*" }; -
Add the policy file to the
policieslist at the top of.box/agent/local/profile.toml. The following TOML example shows the list.policies = ["aws-metadata-block.dw", "policy.dw"] -
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.
| What the agent runs | With no rules | With the three permit rules |
With the forbid rule added |
|---|---|---|---|
|
|
Refused |
Works |
Works |
|
|
Refused |
Works |
Works |
|
|
Refused |
Works |
Refused |
|
|
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 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