Repository navigation
refactor(shell): migrate Box to upstream Strands Shell - #414
Conversation
…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.
|
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 ported security suites and the deliberate identity-check break give good evidence for the kernel move. |
|
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 |
|
Assessment: Request Changes (re-review of The merge from Status since `b9f5ccb`
Checks that held:
|
|
Assessment: Comment (no new findings; the merge is gated only on the upstream pins) I re-reviewed Checks that held
One edge I did not post as a comment: the list of running commands is shared across processes. A background |
…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).
|
Important (blocking): Example: These are the deleted suites:
The only copies left are in 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 |
|
Assessment: Request Changes (re-review of The new pin to upstream #246 makes the pre-start decision work: Checks that held
The remaining merge gate is unchanged: upstream #245 and #248. |
|
Assessment: Request Changes (re-review of
Checks that held
|
|
Assessment: Request Changes (re-review of The merge brings no new findings. One correction: my general comment at 03:48 about "24 deleted security tests" was wrong once Checks that held
|
|
Assessment: Approve (re-review of The merge gate I was holding for is met. The pin Checks that held
Moving each regression into an upstream fix with a restored test made this a clean final round. |
|
Assessment: Request Changes (re-review of The merge resolution itself is sound. The only conflicts are in Checks that held
|
|
@priyasingh2111 all three items from your audit have landed upstream, and Box pins them at |
|
Assessment: Request Changes (re-review of 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 Checks that held
|
|
Important (non-blocking): Example: I ported the suite as a temporary test from
Suggestion: port the suite into |
|
Assessment: Approve (re-review of 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
|
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.
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 atcrates/shell(packagestrands-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 andjustlint exceptions that existed only for the vendored copy are removed too. No CLI flag,box.tomlkey, 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
cat /workspace/frecords["cat", "<redacted>"], and the path stays in thefs:readdecision. Upstream does not say which words the script stated literally. The decisions entry and the telemetry pages say this.mkdir -pworkaround. 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'sKernel::try_statas one metadata decision, somkdir -pmakes one decision for each component, as it did with the vendored copy.kernel_effect_interception.rs::mkdir_p_makes_one_metadata_decision_per_componentpins this for a missing, an existing, and a refused ancestor.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_admittedanda_denied_nested_command_does_not_run, which coversh <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
mainand carry the Shell fixes thatmain's #397 made in the vendored copy. It also includes fixes and additions inprintf,date,find,xargs,curl,grep,ls,ln,readlink,sort,head,jq,echo,set -o pipefail, andsh -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.
just check, orcargo test --workspace --all-features)cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.