Skip to content

refactor(shell): migrate Box to upstream Strands Shell - #414

Merged
ferdingler merged 34 commits into
mainfrom
feature/shell-from-upstream
Nov 13, 2026
Merged

ferdingler merged 34 commits into
mainfrom
feature/shell-from-upstream

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Box built its Shell from a vendored copy of Strands Shell. That copy had drifted far from upstream, and Box's own enforcement lived inside it. So Box could not take an upstream fix without a hand merge, and the copy could never be deleted.

With this change, Box builds against upstream Shell at a pinned revision, 20c642b, and the vendored copy is gone. Box's enforcement lives in its own crate at crates/shell (package strands-box-shell), which holds the kernel the Shell runs on and the checkpoint each effect meets before it happens. The policy adapter and the reach floor plug into that checkpoint, as they did before. The CI and just lint exceptions that existed only for the vendored copy are removed too. No CLI flag, box.toml key, protocol frame, alias, or policy action changes. One interface narrows, with the maintainer's approval: a shell record now redacts every argument that is not a plain flag.

To check it, I ported the vendored Shell's security suites onto the new kernel, and they pass. I broke the identity check, the setuid refusal, the link handling, the pre-start pipeline check, and the never-ran record on purpose, and the tests caught each one. Every suite passes on Linux after a clean build, including the sourced-file cases that waited on upstream. I did not run the macOS suites locally; CI runs them.

Decisions a reviewer cannot see in the diff

  • One Box-owned Shell crate. It holds the checkpoint vocabulary and the kernel, and it does not depend on policy, telemetry, reqwest, or the egress gateway. The policy crate's public surface does not change.
  • Redaction (approved interface change). Before, a word the script stated literally was reported whole. Now cat /workspace/f records ["cat", "<redacted>"], and the path stays in the fs:read decision. Upstream does not say which words the script stated literally. The decisions entry and the telemetry pages say this.
  • Shell messages that upstream captures are forwarded to the Program's output after each call, because upstream does not write them to an installed stderr writer.
  • Every pipeline stage is decided before any stage starts, a host-binary stage included. A stage that was decided but never ran is recorded as indeterminate, and its decision does not carry into a later call.
  • No mkdir -p workaround. Upstream now skips an ancestor it is not allowed to see, so Box's own workaround is removed, and the policy tests for it still pass. Box serves upstream's Kernel::try_stat as one metadata decision, so mkdir -p makes one decision for each component, as it did with the vendored copy. kernel_effect_interception.rs::mkdir_p_makes_one_metadata_decision_per_component pins this for a missing, an existing, and a refused ancestor.
  • The vendored copy's notices file is removed, because the repository no longer holds third-party source.

Follow-up

A follow-up PR I have planned ports the rest of the test coverage that the vendored copy had. The behaviour still holds today, and only these tests are gone:

  • write_visibility.rs: a host write that fails midway, the streaming memory bound, and later commands or Shells that see the whole write.
  • write_cap.rs: the boundary matrix, and an append at the cap that is refused at open.
  • spawn_working_directory.rs: a working directory for each stage, a refused relative directory, and a denied stage that never spawns.
  • kernel_effect_interception.rs: every_nested_command_route_is_admitted and a_denied_nested_command_does_not_run, which cover sh <file>, . file, and the EXIT trap.
  • effect_interceptor.rs: the outcome tests for a denial, a fault, and an indeterminate result.

Related Issues

The pin includes upstream Shell #245, #246, #247, #248, #252, #256, #257, #258, #262, #263, #264, #265, #266, and #267, which fix the regressions the reviews found against main and carry the Shell fixes that main's #397 made in the vendored copy. It also includes fixes and additions in printf, date, find, xargs, curl, grep, ls, ln, readlink, sort, head, jq, echo, set -o pipefail, and sh -c. None of them changes a Box interface.

Type of Change

Other (please describe): the Shell dependency moves from the vendored copy to upstream, and the vendored copy is deleted. Box's interface is unchanged, apart from the approved redaction.

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.

I also cut the Shell kernel tests down with shared helpers and case tables, and removed cases that another suite already covers.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

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.

…vendored copy

## Problem

Box builds against a vendored copy of Strands Shell in `crates/shell`. The copy holds about
5,700 lines of local divergence from upstream, and each upstream fix must be merged into it by
hand. The divergence also holds Box's own enforcement: the `fs:*` decisions, host-folder
serving, host-binary spawns, and Python routing. So Box cannot take upstream fixes, and the
vendor cannot be deleted.

## Solution

Box depends on `strands-agents/shell` at revision `286ac414`. The vendored `crates/shell` and its
macro crate leave the workspace members, because their `mlua 0.11` and upstream's `mlua 0.12`
both link `lua`. The directory stays on disk, and a later change deletes it.

A new crate, `crates/box-shell` (package `strands-box-shell`, import `box_shell`), holds the
Shell's kernel:

- The checkpoint vocabulary: `EffectAttempt`, `EffectInterceptor`, `EffectPermit`,
  `EffectOutcome`, `EffectResult`, `FsOperation`, `FsPairOperation`. These moved from the
  vendor unchanged, so the policy adapter implements the same trait as before.
- `Filesystem`, one Program's filesystem: the Shell's own, and each host folder it serves.
- `ShellKernel`, one Call's `Kernel` over a `Filesystem`. It resolves each path, presents each
  effect at the checkpoint, and acts on the identity the checkpoint judged. It opens parents one
  component at a time with no symlink followed, and refuses an object that moved. It keeps the
  refusal of setuid, setgid, and sticky bits, the symlink target floor, rename destination facts,
  the per-directory glob decisions, one exec decision for a `PATH` walk, and no size cap on a
  host folder. A host write is on the host when the command returns its status.
- `check_command`, `command_finished`, and `command_dropped` give `shell:exec` its decision, its
  status, and status -1 for a command that never ran.
- The `command_fallback` handler decides `shell:spawn` and runs a host binary through the
  embedder's `HostSpawner`, or routes `python` and `python3` to its `ScriptRunner`. A name that
  nothing answers to keeps status 127. Each argument is redacted in a record, because upstream
  does not say which words the script stated.
- `Network`, which the embedder implements for HTTP, and the SSRF floor `check_url_safe`.

The crate does not depend on policy, telemetry, reqwest, or the egress gateway. Box composes it
with the policy adapter and the reach floor. Box's `GatewayNetwork` sends HTTP through the
egress gateway, and Box's closures carry each Call's trace context.

Box sets the Shell limits itself, because `Shell::with_kernel` sets none, and re-arms the
timeout when each Call starts. `verify_direct_binds` checks the kernel's own folder list. The
builder calls that upstream does not have are deleted. `Program::call` forwards the diagnostics
that upstream captures instead of writing to an installed stderr writer.

No CLI verb, `box.toml` key, record, protocol frame, alias, or policy action changes. The
policy crate's `pub use` set does not change.

## Tests

- `cargo build`, `clippy --all-targets`, and `fmt --check` with `--all-features` for
  `strands-box`, `strands-box-policy`, and `strands-box-shell`; the workspace clippy command that
  CI runs; owned warning count 0. `cargo doc` with `-D warnings` for policy and `box-shell`.
- `cargo test --all-features` for `strands-box-shell`, `strands-box-policy` (also without
  features), and `strands-box`.
- `box-shell/tests` holds the vendored Shell's security suites, ported to `ShellKernel`:
  `in_mount_admission_window.rs`, `in_mount_symlink_ops.rs`, `in_mount_symlink_admission.rs`,
  `lstat_follow_on_a_host_bind.rs`, and `kernel_effect_interception.rs` (74 tests). Only the
  cases that test the vendor's internals (`Kernel::resolve`, a mediation layer over a supplied
  kernel) or a read-only bind, which Box does not have, are not ported. With the identity and
  generation check replaced by `true`,
  `a_background_symlink_swap_cannot_beat_the_admission_window`,
  `a_destination_planted_inside_the_admission_window_is_not_replaced`, and
  `a_probe_the_admission_window_refuses_reports_a_failure` fail.
- The policy crate's Shell end-to-end suites drive a real Shell over `ShellKernel` again:
  `policy_shell_fs_e2e.rs`, `temporal_shell_e2e.rs`, `temporal_shell_record_kinds_e2e.rs`,
  `symlink_target_scope_e2e.rs`, and `cross_boundary_e2e.rs`. Every case and name is kept.
- `box-shell/src/host.rs` tests pin the identity rules:
  `a_pin_whose_host_identity_is_not_the_spelling_is_unavailable`,
  `a_symlinked_ancestor_is_neither_pinned_nor_opened`, and
  `a_spelling_under_a_mount_is_translated_to_its_host_identity`.
- `temporal_shell_e2e.rs::an_allowed_command_that_never_runs_records_status_minus_one` pins the
  dropped command.
- `run/broker/kernel/tests/limits.rs` pins each limit and the per-Call timeout.
  `run/broker/kernel/tests/fallback.rs` pins the refused spawn with no spawner, `effect denied`,
  status 127, and Python. `run/broker/shell.rs::a_mount_table_that_is_not_the_declared_set_refuses_to_serve`
  pins the folder check.
- `box/tests/shell_dependency_guard.rs` replaces `shell_egress_client_guard.rs`: it reads the
  resolved upstream source, pins its one network client to `vfs_kernel.rs`, and pins each
  `Kernel` method to one the box's kernel serves. `policy/tests/shell_fs_vocabulary.rs` reads
  `box-shell`'s vocabulary.
- Tests changed for the redaction: `box_telemetry.rs::a_shell_decision_states_its_arguments_and_its_directory`
  asserts a redacted argument, the `box_programs.rs` race tests find the commit by program, and in
  `test-integ` TL-F-07 and `Journal::assert_mediated_entry` prove entry by the `echo` record.
  `decisions.md#a-shell-record-names-only-a-literal-argument` states the new contract.

Still failing, and each waits on an upstream change:

- `run/broker/kernel/tests/streams.rs::a_group_redirected_to_dev_null_writes_nothing_to_an_installed_writer`
  and `::a_group_writing_many_stderr_lines_to_dev_null_finishes_silently`: a group redirect
  does not take stderr from an installed writer. Upstream #245 fixes it.
- `box_shell_cwd.rs::a_denied_tool_directory_stops_every_pipeline_stage`: upstream decides a
  fallback stage only when it starts. Upstream #246 adds the hook.
- `policy_shell_fs_e2e.rs::mkdir_p_below_an_ungranted_parent_is_refused_and_names_the_target`
  and test-integ SH-MKDIR-P: the refusal names a missing refused ancestor instead of the target.
  Upstream #247 fixes `mkdir -p`.
- test-integ SH-SOURCE-JOIN, SH-SOURCE-STATUS, and SH-SOURCE-STOP: a sourced line that ends with
  `&&` or `||` does not join the next line, and a parse error does not name its file and line.
  An upstream fix is coming.

Not run: the macOS suites, which CI runs. `test-integ` ran once on Linux before the last test
changes; its other red cases also fail on `main` on this host. Under load, `mcp_alias_fallback.rs`
fails with "Text file busy" and three `runtime_mcp_start.rs` tests hit their 8-second limit; each
passes on its own.
Comment thread docs/user/telemetry.md Resolved
Comment thread crates/box/src/run/broker/shell.rs Resolved
Comment thread crates/box-shell/src/kernel.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Request Changes

The port is careful, and the checkpoint vocabulary moved over cleanly. One new kernel heuristic gives a wrong result and reveals whether a path exists. The branch also has two gaps against frozen surfaces: one appears on rebase, and one is an undisclosed change to telemetry.

Review Categories

Checks that held:

  • The policy crate's pub use set is unchanged.
  • No security test is #[ignore]d.
  • The egress tests moved into kernel/tests/egress.rs, and none was dropped.
  • The gateway client still trusts only the gateway CA and follows no redirect.
  • The SSRF floor now also refuses every spelling of localhost.
  • With no spawner, a host binary is refused with status 126 and does not run.
  • HostSpawn.env was dropped, but Box's hook ignored it before.
  • The upstream pin already contains the fix(shell): enforce input limits for multiline commands #403 multiline max_input check.
  • The glob and canonicalize limits on host folders are the same as in the vendored copy.

The ported security suites and the deliberate identity-check break give good evidence for the kernel move.

@ferdingler

Copy link
Copy Markdown
Collaborator Author

On the merge gate: agreed. This PR stays unmerged until the pin includes #245, #246, and #248, and no pinned test changes in the meantime. When each one merges, a new commit here moves the revision and wires check_fallback. #247 is no longer needed for green, because 20105f4 restores the vendor's mkdir -p rule in the kernel.

@github-actions

Copy link
Copy Markdown

Assessment: Request Changes (re-review of cba553a)

The merge from main connects the configurable Shell limits to the new kernel correctly. The other two open threads point at code that this head does not change, so they still apply.

Status since `b9f5ccb`

Checks that held:

  • The merge resolution passes the configured limits through, and 0 disables each limit, including the script read.
  • On this head, kernel/tests/limits.rs (6 tests), raised_input_limits_survive_repeated_calls_on_one_program, and the record::config limit tests pass.
  • The merge does not touch crates/box-shell. The changes from feat(box): add experimental Linux x86-64 support #398 are in containment and the Linux platform code and do not reach the Shell kernel.

@github-actions

Copy link
Copy Markdown

Assessment: Comment (no new findings; the merge is gated only on the upstream pins)

I re-reviewed b9f5ccb → cba553a → 20105f4: the merge of main and the mkdir -p fix. All three earlier findings are addressed, and I found no new correctness issue. The only thing that holds the merge is the remaining failing tests, which wait on upstream #245, #246, and #248. You already agreed to that.

Checks that held
  • The skip in create_dir applies only to an ancestor that a running mkdir -p walks. A plain mkdir, [ -d X ] || mkdir X, and an operand that is not an ancestor of another operand all reach CreateDir.
  • The skip returns the same result whether or not the path exists, so it no longer reveals existence.
  • Some spellings don't match the mkdir -p check, such as --parents, command mkdir, or a non-mkdir program. These fall through to the CreateDir decision, so they fail safe.
  • The merge passes the configured max_input and max_output to the Shell process and to the python script read. 0 still means no cap.
  • kernel/tests uses the config defaults instead of the removed constants.
  • The telemetry narrowing is now disclosed and approved, and crates/telemetry/AGENTS.md matches the test.
  • Verified locally: policy_shell_fs_e2e -- mkdir gives 5 passed.

One edge I did not post as a comment: the list of running commands is shared across processes. A background mkdir -p /w/s/x & could let a concurrent plain mkdir /w/s from another process skip its decision. That process would also need its own refused probe of /w/s first. The skipped mkdir returns 0 and has no effect.

…ts pipeline starts

Upstream #246 adds Kernel::check_fallback. The kernel now decides a host-binary or python stage there, before any stage of the pipeline starts, and uses that decision when the stage runs. A decided stage that never runs is recorded as indeterminate. box_shell_cwd.rs::a_denied_tool_directory_stops_every_pipeline_stage passes again. The only other upstream change in the range, #244, edits a comment.
…one owner per case

The host-folder suites share one fixture folder, one runner, and one checkpoint hook in
`tests/support`. Their cases are `host_case!` entries, and the four refused link targets are one
table keyed by the case names they had. The admission-window cases share one hook that changes
the host once. The kernel effect suite drops the cases that another suite owns:

- a_symlink_cannot_launder_a_denied_read: policy temporal_shell_e2e.rs::a_symlink_cannot_launder_a_denied_read
- denying_a_write_effect_blocks_it_under_an_admitted_command: policy_shell_fs_e2e.rs::forbidding_fs_write_blocks_a_write_under_a_permitted_command
- an_unmediated_shell_still_works: policy_shell_fs_e2e.rs::permitted_filesystem_effects_succeed
- a_denied_selected_candidate_does_not_run: policy_shell_fs_e2e.rs::forbidding_the_selected_candidates_exec_probe_keeps_it_from_running
- every_nested_command_route_is_admitted, a_denied_nested_command_does_not_run: upstream tests/command_check.rs::nested_commands_are_checked and ::a_denied_command_does_not_run_and_reports_the_denial
- denying_enumeration_yields_no_matches: temporal_shell_e2e.rs::an_ancestor_wildcard_cannot_enumerate_a_forbidden_directory
- mkdir_p_creates_no_ancestor_whose_probe_is_denied: policy_shell_fs_e2e.rs::mkdir_p_below_an_ungranted_parent_is_refused_and_names_the_target
- a_directory_symlink_cannot_launder_mutations, no_mutating_operation_can_launder_through_a_directory_symlink, mv_through_a_directory_symlink_is_judged_on_its_target: policy_shell_fs_e2e.rs::a_path_rule_holds_through_a_directory_symlink_for_every_operation
- the in-memory halves of test_minus_l_sees_a_host_symlink and rm_on_a_host_symlink_to_a_directory_removes_the_link: upstream's own VFS suite

Each of these defects, introduced alone, fails the named tests: `is_current` returns true
(a_background_symlink_swap_cannot_beat_the_admission_window,
a_probe_the_admission_window_refuses_reports_a_failure,
a_destination_planted_inside_the_admission_window_is_not_replaced); no setuid refusal
(chmod_refuses_setuid_and_leaves_the_host_mode_unchanged); lstat follows (seven host_folders
cases); no pre-start fallback check (box_shell_cwd.rs::a_denied_tool_directory_stops_every_pipeline_stage);
no command_dropped (temporal_shell_e2e.rs::an_allowed_command_that_never_runs_records_status_minus_one).
Comment thread crates/shell/src/kernel.rs Resolved
@github-actions

Copy link
Copy Markdown

Important (blocking): 465d0de deletes three ported security suites from crates/box-shell/tests, 24 tests in all, and the commit message does not mention it. After this commit, no test in the workspace pins the behavior that the PR description lists under "In the Box kernel".

Example: These are the deleted suites:

  • in_mount_symlink_admission.rs (3 tests), including a_symlink_escaping_the_mount_is_refused.
  • in_mount_symlink_ops.rs (12 tests), including chmod_refuses_setuid_and_leaves_the_host_mode_unchanged, ln_s_to_a_target_that_climbs_out_of_the_bind_is_refused, and ln_s_to_an_absolute_target_is_refused.
  • lstat_follow_on_a_host_bind.rs (9 tests).

The only copies left are in crates/shell/tests, and that vendored crate is outside the workspace, so they never run. The description says "I ported the vendored Shell's security suites onto the new kernel, and they pass". I restored the three files from 20105f4 onto 465d0de, and all 24 tests pass. So the pin change did not break them.

Suggestion: Restore the three files. If the deletion was intended, say why in the commit and name the tests that now cover the setuid refusal, the link target floor, and the no-follow lstat on a host folder.

@github-actions

Copy link
Copy Markdown

Assessment: Request Changes (re-review of 465d0de)

The new pin to upstream #246 makes the pre-start decision work: a_denied_tool_directory_stops_every_pipeline_stage passes again. But two problems block the merge: decisions left behind when a stage never runs, and 24 deleted security tests. Both are in the comments above.

Checks that held
  • One decision per fallback stage in a pipeline that runs fully. The stage reuses its pre-start decision and is not decided twice.
  • A refused fallback stage stops the whole pipeline with 126 before any stage starts. Earlier check_command permits go to command_dropped, which Shell handles.
  • Each Decided variant keeps the route it had before (Python, not found, host spawn). literal is still all false, which matches the approved redaction.
  • shell_dependency_guard.rs lists check_fallback as served by Box.
  • The pin range 286ac41..9bf86aa contains only feat(policy): split the ip attribute into ip4 and ip6 #244 (a comment) and feat(policy): bind a tool pack on the program file and the command name #246.

The remaining merge gate is unchanged: upstream #245 and #248.

Comment thread crates/shell/src/kernel.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Request Changes (re-review of 20105f4 → 465d0de → 850486c)

465d0de moves the pin to 9bf86aa and wires check_fallback. 850486c reorganizes the kernel tests. One new blocking issue is inline: a fallback stage that is decided but never started keeps its permit across Calls. Once that is fixed, the only thing holding the merge is the remaining upstream pins (#245, #248).

Checks that held
  • Pre-start decision: the pin now decides each python, not-found, and host-program stage before the pipeline starts. If any stage is refused, the pipeline stops with 126, and a_denied_tool_directory_stops_every_pipeline_stage passes. A stage run without a pre-start check, such as a nested route, is still decided inline.
  • Test reorganization (850486c):
    • All 24 ported host-folder cases are in host_folders.rs, with assertions as strong as the originals: lstat, link target floor, setuid refusal, and in-mount links.
    • When I restored the three original suites on 465d0de, all 24 cases passed.
    • Each case dropped from kernel_effect_interception.rs that the commit message gives a Box owner for has a test of that name in crates/policy/tests. I did not check the upstream tests/command_check.rs owners for the nested-route cases.
  • Shell dependency guard: shell_dependency_guard.rs lists check_fallback as served by Box.

@github-actions

Copy link
Copy Markdown

Assessment: Request Changes (re-review of 850486c → 861b4a6, the merge of main that brings in #393)

The merge brings no new findings. crates/box-shell/src is the same as in 850486c, so the blocking inline thread on crates/box-shell/src/kernel.rs:973 still applies. A fallback decision whose stage never starts can still be carried into a later Call. Two inline comments describe that same issue; please treat them as one thread.

One correction: my general comment at 03:48 about "24 deleted security tests" was wrong once 850486c landed. All 24 cases are in host_folders.rs, so please ignore that comment.

Checks that held
  • Monty fetch() floor: fetch.rs calls box_shell::check_url_safe, which delegates to upstream's floor at 9bf86aa. That floor already refuses 0.0.0.0/8, 168.63.129.16, 100.100.100.200, ::ffff:0:0:0/96, 64:ff9b::/96, and 64:ff9b:1::/48. I ran fix(shell): refuse translated and platform metadata addresses before transport #393's a_fetch_to_a_translated_or_platform_metadata_literal_is_refused_before_transport on this head, and it passes.
  • curl floor: curl in the Box kernel (kernel.rs:152) uses the same check_url_safe. So the claims in docs/user/security.md, docs/user/monty.md, and docs/user/policy.md match the code that runs.
  • Vendored copy: the crates/shell changes from fix(shell): refuse translated and platform metadata addresses before transport #393 touch only the vendored copy, which is outside the workspace. They have no runtime effect.

The merge gate is unchanged: upstream #245 and #248.

@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review of 4fb510d → 14c9392). This replaces my earlier Request Changes.

The merge gate I was holding for is met. The pin 46eb349 includes strands-agents/shell #256, #258, #262 and #263. At this head, Kevin's #1, #4 and #6 and the audit's items 1–3 no longer reproduce, and the description now lists these fixes. The one inline note is a test that should check the exact recorded status. It doesn't block the merge.

Checks that held
  • serves (python/python3 ahead of PATH): I put an executable /tmp/python3 that prints SHADOW first on PATH. Monty still answered every route I tried:

    • plain, command, exec
    • xargs, find -exec, sh -c, ( … )
    • hash python3; python3
    • an alias, which a non-interactive shell does not expand

    A shell function named python3 still wins, as the upstream trait documents. command -v prints python3. type prints "is a shell builtin". With no script runner, serves is false and the command goes to the host spawn decision, as before.

  • Deadline after $(…) (Kevin ci: Bump taiki-e/install-action from 2.87.21 to 2.87.22 #1 and audit item 2): I ran 11 shapes with a host program that never finishes. None left a late write and each returned status 1:

    • a word in an argument, X= as a prefix and as an assignment, a pipeline, a redirect target
    • nested $(…), rm -f, >> to an existing file, [ … ] ||
    • sleep and an endless lua loop inside $(…)

    A Python runner that blocks the thread, and one that awaits, also leave no late write under $(…) or after ;. test: separate integration runtime discovery from fixture execution #257 is still open, but I found no case at this pin that still needs it.

  • Piped compounds under policy (ci(rust): Bump mlua from 0.11.6 to 0.12.1 #4): while, until, for, case, if, { }, ( ) and a function piped from printf are each decided on their own commands. compound | compound fails to parse. Old Box at 61ade09 fails the same way, so this is not a regression.

  • Restored tests: host_spawn_cleanup.rs (cancelling wait, dropping a Shell, an expired substitution) passes at this pin.

  • Other test change: clearing the outcomes after setup in a_probe_the_admission_window_refuses_reports_a_failure only leaves out the stat that ln now makes during setup.

  • Gates:

    • cargo fmt --all --check and clippy with -D warnings on strands-box-shell, strands-box and strands-box-policy are clean.
    • Every strands-box-shell suite passes. run::broker passes 389 of 389, and every strands-box-policy suite passes.
    • No new #[ignore].

Moving each regression into an upstream fix with a restored test made this a clean final round.

@github-actions

Copy link
Copy Markdown

Assessment: Request Changes (re-review of 14c9392 → 56248b7, the merge of main). The earlier Approve no longer holds: at this head the PR regresses main's #397, and 26 tests fail on purpose until upstream Shell lands its fixes.

The merge resolution itself is sound. The only conflicts are in Program::adopt, which now takes both timeout and input_limit, and in its four call sites, and each is resolved correctly. #431's phantoms and #416/#410 merged cleanly. What blocks the merge is the gate the description already lists: shell#265 and the stdin PR, which has no link yet, plus shell#264. On top of that, the one inline comment asks for the Claude Code preamble suite to be ported and added to that gate.

Checks that held
  • Conflict resolution: --remerge-diff shows only program.rs, host.rs and the two kernel test call sites. set_channel_reader replaces set_outside_reader, as the description says.
  • The failing tests match the description: I counted 13 of 23 in main_shell_semantics and 13 in run::broker::host, and each is named in the description. Every broker failure reads stdin through $(cat), except the Lua one. So they come from the upstream stdin gap, not from a broken limit or policy check. For example, eval "$(cat)" gets an empty string, so no forbidden command runs.
  • Forwarded stdin left open: I ran 15 commands with forwarded stdin left open: python3 -c, jq -n, sh -c, $(echo), ( ), a piped group, xargs, find, head -c and others. Each one finishes, and head -c 3 reads the forwarded input. Only lua -e waits, which is the documented shell#264 item.
  • fix(shell): give the hosted Shell each route's phantom #431 phantoms: build_on still sets the phantoms before PWD, HOME and USER, and the three new host tests pass. Upstream Lua's os.getenv and io.popen read proc.env, not the daemon's process environment, so the premise of the_shell_cannot_read_the_daemons_resolved_secrets holds. That test only runs where namespaces are available, so it was skipped here.
  • builtin prefix: builtin cd, command cd and builtin eval 'cd …' are each refused under a cd rule.
  • I reverted all temporary probe tests.

@ferdingler

Copy link
Copy Markdown
Collaborator Author

@priyasingh2111 all three items from your audit have landed upstream, and Box pins them at 8a203dc: background jobs stop on drop or a cancelled wait (strands-agents/shell#258), a command stops when its substitution uses up the deadline (#256, #257), and a sleep the deadline cuts short reports failure (#256). The restored tests pass: host_spawn_cleanup.rs, an_expired_substitution_cannot_start_following_commands_or_redirects, and `a_sleep_the_deadline_cuts_short_records_a_nonzero_status". The Lua admission and egress cases are ported too.

Comment thread crates/box/src/run/broker/program.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Request Changes (re-review of 56248b7 → 49c70cb: the pin moves to 8a203dc, and alias stdin is now forwarded with set_outside_reader).

The new pin fixes nearly every failure listed in the earlier merge gate. One #397 contract is still broken: the Shell deadline doesn't stop a command that is reading forwarded stdin. That blocks the merge, and it's in the inline comment on program.rs, along with the description's stale pin and testing claim.

Checks that held
  • Test results: main_shell_semantics.rs and the other strands-box-shell suites now pass, and so do 1036 of the 1037 strands-box lib tests. The only failure is the deadline test above. The other integration test failures are environmental: no namespaces, x86 needs EXPERIMENTAL_X86_SUPPORT, and cargo metadata runs offline. shell_dependency_guard passes 3/3 once I fetched the dependencies.
  • set_outside_reader: this matches feat(shell): forward a Shell alias's stdin to its command #397's documented Lua contract (docs/user/shell.md: "reads it as empty and never waits"). Lua exits on forwarded open stdin in 16 shapes, including subshell, group, function, $(…), a pipe out, sh -c, eval, if, for, & plus wait, and 2>&1. A pipe inside one command still reaches Lua's stdin.
  • Upstream propagation: upstream carries the outside mark through transfer_fd, dup2 and take_fd/put_fd, so forked stages keep it.
  • Earlier rg finding: the Claude Code snapshot's if ! (subshell) check is fixed by shell#265 at this pin.
  • I reverted all temporary probes, and the worktree is clean.

@github-actions

Copy link
Copy Markdown

Important (non-blocking): main's crates/shell/tests/claude_code_preamble.rs and its fixture claude-code-snapshot-script.sh were deleted with the vendored copy. They are not ported, and the description's Follow-up list doesn't mention them. They are the only tests that run the commands Claude Code, an unmodified agent, actually sends.

Example: I ported the suite as a temporary test from 88e8c199. The only changes were Shell::builder() → support::builder() and dropping the one interceptor test, whose behaviour I checked separately: builtin cd is still refused under a cd rule.

  • At 56248b7: it caught a real regression. The snapshot's if ! (unalias rg; command -v rg) >/dev/null 2>&1; then function rg … took the else branch, so the agent lost its rg wrapper. shell#265 fixes that.
  • Now: 19 of 20 pass.
  • Still failing: shopt_records_state_and_refuses_an_unknown_name. After shopt -s extglob, shopt -q extglob returns 1 and shopt -p extglob prints shopt -u extglob. Claude Code's snapshot saves shopt -p and sources it back, so this setting is silently lost between calls. None of the pinned upstream PRs touches shopt.

Suggestion: port the suite into crates/shell/tests, or add it to the Follow-up list. Only the builder call needs to change. File the shopt state gap upstream, or record it as an accepted difference.

@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review of 49c70cb → 7b72356, a pin-only change from 8a203dc to 20c642b, which adds shell#267).

The blocking deadline finding is fixed. A forwarded-stdin read now stops at the Shell deadline, and no merge-gate item is left open. The Claude Code preamble port is a non-blocking follow-up.

Checks that held
  • What the pin changes: the upstream diff 8a203dc..20c642b touches only io::stdin(), which is now bounded by proc.deadline, FdReader, read, grep and Lua's pre-read, plus a syn bump. No Box interface changes, and Cargo.lock is consistent with a clean build.
  • Deadline: 26 shapes that read stdin end at the 2 s deadline with status 1 and the timeout message. None runs its follow-on command, including after ||, if and !.
  • Recorded status: the kernel records a nonzero status for each command the deadline stops.
  • No-input-needed and Lua cases: commands that don't need forwarded input still finish at once, and Lua still reads forwarded input as empty.
  • Tests: all 417 run::broker tests pass, and so do all suites in strands-box-shell and strands-box-policy. The description's pin and testing claims now match the code.
  • I reverted all temporary probes, and the worktree is clean.

@ferdingler
ferdingler merged commit 7728614 into main Nov 13, 2026
26 checks passed
@ferdingler
ferdingler deleted the feature/shell-from-upstream branch November 13, 2026 19:52
hanaduy added a commit that referenced this pull request Nov 16, 2026
Review asked that Box not know about Python installs: with Monty off, Python is an ordinary tool
the operator declares and grants, and Box special-cases `python3` only to run Monty. So this
restores the branch to #417's state and drops what the earlier commits on it added:

- install detection and protection (`run/python_install.rs`, the refused writes into the install);
- the grants Box added for a Python tool, including the libraries and the certificates;
- `[tool.python]` answering both names, the 126 refusal when no Python tool is declared, the
  write-only stdin and its stderr line, and the read-only install line;
- the Shell hooks those needed in the vendored Shell, which `main` has since replaced (#414).

The `monty = false` switch comes back on top of `main` in a later commit. The containment fix for
a link chain through a linked folder moves to its own pull request, since it affects any tool.
hanaduy added a commit that referenced this pull request Nov 16, 2026
After the revert, this branch holds only #417, which main has as 174fe80, so the merge takes
main's tree. That includes #414, which replaced the vendored Shell.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants