Skip to content

test(shell): pin that sh FILE is decided as shell:exec on sh - #472

Merged
priyasingh2111 merged 4 commits into
mainfrom
feature/sh-file-judged-as-shell-exec
Nov 17, 2026
Merged

priyasingh2111 merged 4 commits into
mainfrom
feature/sh-file-judged-as-shell-exec

Conversation

@priyasingh2111

@priyasingh2111 priyasingh2111 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

Human readable section

Problem: When an agent runs sh FILE, Box asked policy about the wrong program. It looked up sh on the host and asked whether that host program (for example /usr/bin/bash) may start. But the host sh never started. The Shell read the file and ran it itself. So a policy rule that forbids sh did not stop sh FILE, and the answer could change from one machine to another.

Solution: #414 already fixed the behaviour: Box now knows that sh and lash are the Shell's own programs, so it asks policy about sh as a program the Shell runs (shell:exec). This PR adds tests that check both the decision and that no host program starts. The tests fail if the old behaviour comes back. It also fixes a Box test that wrongly relied on the host sh (it now runs a real host program in its own sandbox), and lists sh and lash in the user docs, with the policy names each one gets. No product code changes.

Trade-off: Policies now see sh FILE as shell:exec. A policy with a broad shell:exec permit now allows sh FILE, the same as . FILE, and a forbid shell:spawn on /bin/sh no longer matches it. To block it, forbid shell:exec where context.input.program is "sh" or "lash". Policy sees them as two names, and /bin/sh and /bin/lash appear as sh and lash. This change shipped with #414 and needs maintainer sign-off.

Details

sh FILE and lash FILE run the file in the Shell, and no host program starts. An earlier Shell decided sh FILE as shell:spawn on the host sh that PATH found, such as /usr/bin/bash. So a forbid shell:exec on sh did not stop sh FILE, and the action that governed the command depended on the operator's host.

The move to the upstream Shell (#414) already decides sh FILE as shell:exec on sh. This PR adds no product code. It pins that decision, and it removes the two places that still assumed the old behaviour:

  • sh_script_admission.rs records each decision and each host-spawner call for sh FILE, lash FILE, /bin/sh FILE, a #!/bin/sh script in the memory filesystem, and a refused sh. It declares sh and lash as the host /bin/sh, so the tests can fail on every host, including a host with no sh on PATH.
  • box_programs.rs::a_program_the_box_never_saw_behaves_like_a_unix_program ran sh FILE with a shell:spawn permit for sh and a [tool.sh] table, because it believed the host sh ran the script. The Shell ran it, so the grant hid the defect, and the test checked no host program. It now runs the script as a declared [tool.faketool], so it is decided as shell:spawn on faketool and runs in its own sandbox. When the permit names another program, the test fails with status 126.
  • docs/user/shell.md lists sh and lash among the interpreters the Shell implements. It says that policy sees them as two names, and that /bin/sh and /bin/lash appear as sh and lash.

Policy-visible behaviour. The change already shipped in #414, and this PR does not change it. Operators should know about it:

  • The shipped example policies (a broad shell:exec permit and no spawn permit) refused sh FILE before refactor(shell): migrate Box to upstream Strands Shell #414 and allow it now. That is the same reach as . FILE.
  • A forbid shell:spawn aimed at /bin/sh no longer matches sh FILE. Use forbid shell:exec on context.input.program == "sh".

Scope limits.

  • A #!/bin/sh script in a home or the workspace is a program named by a path, so shell:spawn still decides it. Only sh FILE, /bin/sh FILE, and a script in the memory filesystem run in the Shell.
  • sh with no file and echo CMD | sh give status 0 and run nothing. That is an upstream Shell defect, and this PR does not fix it.

Related Issues

Internal security finding: sh FILE was decided as shell:spawn on a host program that never ran.

Type of Change

Bug fix (regression tests and docs for a fix that landed in #414)

Testing

  • sh_script_admission.rs: 7 passed, also with PATH=/nonexistent. They include /bin/lash FILE and a rule on sh alone that does not refuse lash.

  • Guard proof: check_command was made to send sh/lash through check_fallback, which is the reported defect. All 5 tests failed ([Spawn("/bin/sh"), Exec("echo")], and status 0 in place of 126). The change was then reverted.

  • cargo test -p strands-box-shell --all-features: 137 passed.

  • cargo test -p strands-box --all-features --no-fail-fast: 1618 passed. Two data_volume unit tests fail only when TMPDIR is on a non-root volume, and pass with the default TMPDIR.

  • box_programs: 22 passed, 2 ignored. site_manifest: 27 passed.

  • cargo clippy --all-targets --all-features: no warnings in the changed crates. cargo fmt --check is clean.

  • Checked on macOS only. Linux, test-integ, and scripts/test-all.sh did not run here and are left to CI.

  • I ran the relevant suites (cargo test -p strands-box-shell -p strands-box --all-features)

  • If I touched Rust, I ran cargo fmt and cargo clippy --all-targets --all-features on the changed crates

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions github-actions Bot added Area - Shell/Monty Area - policy-engine chore Maintenance tasks, dependency updates, CI changes, refactoring with no user-facing impact labels Nov 16, 2026
@priyasingh2111
priyasingh2111 marked this pull request as ready for review November 16, 2026 22:29
Comment thread crates/box/tests/box_programs.rs Resolved
Comment thread docs/user/shell.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment

The new sh_script_admission.rs pins are correct, and they pass at cd3f9b0. I left two non-blocking findings inline. First, the edited box_programs.rs test no longer runs a program on the host, so the box suite loses its only check that such a program's stderr stays separate. Second, the docs describe sh and lash as one interpreter, but policy sees two names, so a rule on sh alone leaves lash FILE open.

Assumptions and rules checked that held
  • sh FILE, /bin/sh FILE, command sh FILE, exec sh FILE, x=sh; $x FILE, xargs sh, find -exec sh, and sh -c are all decided as Exec("sh") with no host spawn, and a refused sh returns 126. I probed each case with the PR's harness.
  • A #!/bin/sh script in the memory filesystem is decided as sh. A #!/usr/bin/env sh script in memory is decided as shell:spawn on the host env. So the PR description's "a script in the memory filesystem runs in the Shell" covers only the #!/bin/sh form. The user docs do not make that claim.
  • /usr/bin/sh FILE is still decided as shell:spawn on the host file (/usr/bin/dash here). That matches the doc's "program named by a path" row, and default-deny refuses it.
  • support::Builder::programs is limited to tests. No pub use set, frozen surface, or Cargo.lock changed (root AGENTS.md).
  • No security test was deleted or #[ignore]d (root AGENTS.md, Foundational premises).
  • Ran: cargo test -p strands-box-shell --all-features --test sh_script_admission (5 passed). box_programs::a_program_the_box_never_saw_behaves_like_a_unix_program compiled, but it returned early because the namespace launcher cannot run on this runner. It was not exercised.

The guard proof in the description, where the author put the defect back and saw all 5 tests fail, makes these regression pins credible.

Comment thread docs/user/shell.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Request Changes

Re-review of 45f426c against cd3f9b0. Both earlier findings are addressed in intent. The only remaining problem is in the rewritten box_programs test. On Linux, the new [tool.faketool] table does not grant the script's #!/bin/sh interpreter, so I expect Box to refuse the launch. That would make the test fail on the Linux aarch64 CI run. The details and a fix are in the reply on the earlier box_programs.rs thread. Once that is fixed and the test passes on Linux, this looks ready.

Checked at this head, and held
  • sh_script_admission.rs passes all 7 tests here, including the new /bin/lash and lash-under-a-sh-rule cases.
  • The rewritten test names a host program again: faketool by its bare name is decided as shell:spawn, the permit is limited to program == "faketool", and the doc comment matches what the test does.
  • The docs/user/shell.md interpreter list now says that policy sees sh and lash as two names, and that . and source also run a file. That matches the probed behaviour.
  • Request::workspace() is limited to tests, and no frozen surface or Cargo.lock changed (root AGENTS.md).
  • Not run: box_programs on Linux aarch64. This runner is x86_64, where the box does not start.

@github-actions

Copy link
Copy Markdown

Assessment: Approve (provided the Linux aarch64 CI passes)

Re-review of d5e2b37 against 45f426c, plus 3a28341, which the branch now points at. Both open items are fixed, and I found nothing new.

Checked at this head, and held
  • box_programs.rs::a_program_the_box_never_saw_behaves_like_a_unix_program now grants the canonical /bin/sh through read_file. That matches the Linux rule in crates/box/AGENTS.md: "every interpreter needs coverage from that process's original filesystem grants". It is also the grant script_interpreter_grants.rs uses. On macOS the extra grant changes nothing.
  • The {{workspace}} escapes in format! produce the same {workspace} placeholder as before.
  • The docs/user/shell.md row for context.input.program (3a28341) matches the probed behaviour: a /bin/<command> path reaches policy as the bare name, and another absolute path is decided as shell:spawn.
  • No product code, frozen surface, or Cargo.lock changed.
  • Not run here: box_programs on Linux aarch64. This runner is x86_64, where the box does not start. CI's ubuntu-24.04-arm job is the only Linux proof, so check its result before you merge.

Thanks for the quick fixes and for checking each one with the harness.

@github-actions

Copy link
Copy Markdown

Assessment: Comment (this replaces my earlier "Approve")

Re-review at 3a28341 against d5e2b37. The only change is the context.input.program row in docs/user/shell.md. When I approved before, I checked that row only against the PR's shell-crate harness. When I checked it through Box's own kernel, it was wrong for /bin/python3 and /bin/python. Those paths are decided as host programs (shell:spawn), not as python3 (shell:exec). The details and a narrower wording are in the reply on the docs thread. This is not blocking, because default-deny still refuses those host programs.

Checked at this head, and held
  • d5e2b37: the read_file grant on the canonical /bin/sh covers the interpreter of the #!/bin/sh line. Box selects a declared tool with Granted (hosted.rs), and for a leaf stated_interpreter_operation accepts a read_file grant that covers the resolved file.
  • The other /bin/<command> names I probed reach policy as their bare names: printf, test, find, xargs, jq, curl, true, echo, cat, grep, lua, sh, lash.
  • /usr/bin/grep, /usr/bin/cat, and /bin/git are decided as shell:spawn, as the row says.
  • No product code, frozen surface, or Cargo.lock changed. I reverted my temporary probe test.
  • Still not run here: box_programs on Linux aarch64. This runner is x86_64. The author said they will run it before the PR leaves draft.

## Problem

`sh FILE` and `lash FILE` run the file in the Shell. No host program starts. An earlier Shell
decided `sh FILE` as `shell:spawn` on the host `sh` that `PATH` found, for example
`/usr/bin/bash`. So a `forbid shell:exec` on `sh` did not stop `sh FILE`, and the decision changed
with the operator's host. The move to the upstream Shell made the decision `shell:exec` on `sh`,
but no test pins it. A Box test still has a `shell:spawn` permit for `sh` and a `[tool.sh]` table,
because it thinks that the host `sh` runs the file. The user docs do not list `sh` as a Shell
interpreter.

## Solution

- Add `sh_script_admission.rs`. It records each decision and each call to the host spawner for
  `sh FILE`, `lash FILE`, `/bin/sh FILE`, a `#!/bin/sh` script in the memory filesystem, and a
  refused `sh`. It declares `sh` and `lash` as the host `/bin/sh`, so a decision that reached the
  host lookup gives a spawn on every host, with or without `sh` on `PATH`.
- Add a `programs` passthrough to the shell test support builder.
- Remove the `shell:spawn` permit and the `[tool.sh]` table from
  `a_program_the_box_never_saw_behaves_like_a_unix_program`. `PERMISSIVE` is sufficient.
- List `sh` and `lash` as interpreters in `docs/user/shell.md`.

No product code and no interface change.

## Tests

- `sh_script_admission.rs`: 5 tests pass. Each one asserts the decisions and that the host spawner
  ran nothing. They also pass with `PATH=/nonexistent`.
- Proof that the guard fires: `check_command` was changed to send `sh` and `lash` through
  `check_fallback`, which is the reported defect. All 5 tests failed (`[Spawn("/bin/sh"), ...]`, and
  status 0 in place of 126). The change was then removed.
- `box_programs.rs`: 22 passed, 2 ignored, with `PERMISSIVE` only.
- `cargo test -p strands-box-shell --all-features`: 135 passed.
- `cargo test -p strands-box --all-features --no-fail-fast`: 1618 passed. Two `data_volume` unit
  tests fail when `TMPDIR` is on `/Volumes/workplace`, and pass with the default `TMPDIR`.
- `site_manifest`: 27 passed. Clippy has no warnings in the changed crates. `fmt --check` is clean.
- Run on macOS only. Not run: Linux, `test-integ`, and `scripts/test-all.sh`.

Not in scope: `sh` with no file and `echo CMD | sh` give status 0 and do nothing. This is an
upstream Shell defect. A `#!/bin/sh` script in a home or the workspace is a program named by a
path, so `shell:spawn` decides it.
…nce test, and document that sh and lash are two policy names
@priyasingh2111
priyasingh2111 force-pushed the feature/sh-file-judged-as-shell-exec branch from 3a28341 to e873a38 Compare November 17, 2026 00:52
@github-actions

Copy link
Copy Markdown

Assessment: Comment

Re-review at e873a380. The branch was rebased onto 941fd272, and git range-diff shows that all four commits are unchanged from cd3f9b0…3a28341. The new main does not touch the Shell, the shell tests, or the interpreter-grant code. It only adds experimental x86-64 support, which let me run the box tests for real this time.

The only open item is still the /bin/python3 and /bin/python exception in the context.input.program row of docs/user/shell.md. It is described in my reply on that thread, and it is not blocking. With that row narrowed, I would approve.

Checked at this head, and held
  • On Linux x86-64 with EXPERIMENTAL_X86_SUPPORT=TRUE, box_programs passes (22 passed, 2 ignored), including the rewritten a_program_the_box_never_saw_behaves_like_a_unix_program with a real box launch.
  • Without the read_file grant on /bin/sh, that test fails, because the box refuses the [tool.faketool] table for the unlisted interpreter. So the grant is required, and it is enough.
  • sh_script_admission.rs: 7 passed.
  • No product code, frozen surface, or Cargo.lock changed. My temporary edit is reverted, and the working tree is clean.
  • Not run: Linux aarch64 and macOS.

@priyasingh2111
priyasingh2111 merged commit aa18761 into main Nov 17, 2026
22 checks passed
@priyasingh2111
priyasingh2111 deleted the feature/sh-file-judged-as-shell-exec branch November 17, 2026 01:25
hanaduy added a commit that referenced this pull request Nov 17, 2026
One conflict, in docs/user/shell.md: main rewrote the interpreters line to cover sh and lash
(#472), and this branch added that python and python3 are external programs with
monty = false. The resolved line keeps both.
freeqaz added a commit to freeqaz/box that referenced this pull request Nov 18, 2026
Brings the containment fix that permits kill and rt_sigtimedwait for a
workload that runs an init such as tini (dc1d8e8). Without it a workload
started under tini dies at start.

The fix branch sits on upstream 5ed679f (the v0.2.3 release commit), so
this merge also brings in the four upstream commits after 941fd27, the
base of dogfood/main:

- e8b4ced docs(design): add path locations design doc (strands-agents#461)
- aa18761 test(shell): pin that `sh FILE` is decided as `shell:exec` on
  `sh` (strands-agents#472)
- 1ccd68a feat: add Linux x86-64 release downloads (strands-agents#475)
- 5ed679f feat: add Linux filesystem policy operations (strands-agents#193)

No conflicts. Git merged crates/box/{AGENTS.md,Cargo.toml},
crates/box/src/command/run.rs, crates/box/src/record/config/mod.rs,
crates/box/src/run/contain/boundary.rs, crates/box/src/run/hosted.rs and
docs/user/native-filesystem-policy.md automatically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - policy-engine Area - Shell/Monty chore Maintenance tasks, dependency updates, CI changes, refactoring with no user-facing impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants