Repository navigation
fix(policy): decide an undeclared name of a grammar-bound file as shell:spawn - #352
Merged
Merged
Conversation
…ll:spawn ## Problem On macOS, `/usr/bin/git`, `make`, `clang`, and about 75 other names are hard links to one launcher file. The launcher selects the tool from the name that calls it. The tool grammar bindings refused a spawn of a bound file under a name that no `[tool]` declares, before policy. Thus a git grammar on `/usr/bin/git` refused `make`, and no policy could permit it. To prevent this, a startup check refused a grammar on a `[tool]` or a stdio `[mcp]` command file with more than one name. Thus a git grammar was not usable on macOS `/usr/bin/git`. ## Solution `GrammarBindings` still binds on the pair (file identity, called name). A declared name keeps its grammar action. A name that no grammar binds is not covered, so `shell:spawn` decides it. This is also true when the file was replaced and the name is not a bound name. These refusals stay: a replaced bound file under a bound name, a bare bound name whose file is gone or replaced, and bindings from another engine. The startup refusal of a grammar on a command file with several names is removed from `[tool]` and from stdio `[mcp]`. The `Starter` distinction between an agent spawn and an MCP server start is removed, because only the undeclared-name refusal used it. A server binding still adds the same (file, name) pairs as before. `declare_server` stays, and now does the same as `declare_tool`. No public name changes. The docs that the change made wrong are updated: `docs/user/shell.md`, `docs/user/policy.md`, `docs/user/config.md`, `docs/design/policy.md`, and `docs/design/architecture.md`. `docs/user/shell.md` now tells the operator to pin a `shell:spawn` permit on both `program` and `program_path`, because a link to a bound file under another name is a `shell:spawn`. ## Tests - `bindings.rs::a_file_with_several_names_binds_the_declared_name_and_leaves_each_other_name_a_spawn` pins that hard links `make` and `clang` of a bound `git` file are not covered, and `git` at each name is parsed. - `shell.rs::empty_bindings_decide_every_spawn_as_the_shell_spawn_path_does` has a new case, a grammar on the same file under another name. Each other name decides the same as a direct `shell:spawn`. - `shell.rs::a_replaced_file_is_refused_whatever_the_policy_permits`, `a_replaced_shim_binary_is_refused_under_its_bound_name`, `a_refused_spawn_enters_history_as_a_shell_spawn_request`, and `bindings.rs::a_replaced_file_at_a_bound_path_is_refused` pin the refusals that stay. - `bindings.rs::a_server_name_on_a_bound_file_binds_no_grammar` and `hosted.rs::an_mcp_server_that_shares_a_bound_file_starts_as_shell_spawn_by_its_own_name` pin that a server name gives no grammar coverage, and that the bound name keeps its grammar. - `hosted.rs::an_mcp_server_that_a_grammar_binds_starts_when_its_file_has_several_names` pins that the startup refusal is gone for a stdio `[mcp]`. - `hosted.rs::a_grammar_on_apples_git_binds_git_and_leaves_its_other_names_to_shell_spawn` runs on macOS only. It uses the real `/usr/bin/git`. - The reviewer put back the old refusal, and 7 tests failed. The reviewer made the replaced-file refusal cover every name, and 4 tests failed. On Linux, `cargo test -p strands-box-policy` passed with and without `--all-features`. Clippy showed no warnings in the policy crate or in `strands-box`, and `cargo fmt --check` passed. In `strands-box`, each grammar, binding, and commands unit test passed. 69 other unit tests failed on this devbox because its mount table is not valid for the installation inventory. They are not related to this change. I did not compile or run the macOS test here. CI runs it.
ferdingler
added a commit
that referenced
this pull request
Nov 6, 2026
8 tasks done
|
Assessment: Request Changes The macOS fix is correct for the names the host installs. The one problem is in the inline comment: removing Assumptions and rules checked that held
|
…er declares, per review
ferdingler
added a commit
that referenced
this pull request
Nov 6, 2026
|
Assessment: Approve f9cf38b closes the grammar bypass through an MCP server's name that I raised earlier, and it keeps the macOS fix. I found no new problems. Assumptions and rules checked that held at f9cf38b
|
akujane
reviewed
Nov 6, 2026
akujane
approved these changes
Nov 6, 2026
8 tasks done
8 tasks done
hanaduy
pushed a commit
that referenced
this pull request
Nov 10, 2026
## Problem The hosted Shell finds a bare name, such as `git`, on the `PATH` of the `run` process. Box then selects a `[tool]` by the identity of the file that it found. A `[tool]` whose command file is not the first match on that `PATH` cannot run by its name. On macOS with full Xcode, the `box/git` pack of Box CLI runs `<developer>/usr/bin/git`, because the Apple stub `/usr/bin/git` exits 71 in the sandbox. The Shell finds the stub first, no `[tool]` names it, and policy decides `shell:spawn` on `/usr/bin/git`. So `git` does not work in the box. The same gap occurs for Homebrew git behind `/usr/bin`, and for a tool whose `command` resolves on its own `env.PATH` to a different file than the operator's `PATH` finds. A workaround in Box CLI changed the `PATH` of the trusted process for every bare name (strands-agents/staging-boxy#365). ## Solution A bare name that a `[tool]` answers to runs the command file that the run opened and checked at startup, before any `PATH` lookup. - A `[tool]` answers to the last component of its `command[0]`, not to its table label. A `[tool]` with a grammar answers only when the grammar's `program` is that name. A grammar whose `program` differs keeps the startup `PATH` check from #358 and the `PATH` lookup. - Box leaves out each name that the Shell runs itself (builtins, Shell commands, `sh`), because the Shell's own program keeps precedence. - A name that tables with different files answer to stays on `PATH`, as before. - When the declared file is gone, the name is not found. The Shell does not search `PATH` for another file, so the refusals of #352 still apply. - `program` stays the name that the agent typed. `program_path` is the tool's file. The spawn still needs a `shell:spawn` permit or a grammar action, so the change adds no authority. - `run` prints one startup line for each name and the file it runs, and one for each shared name. Interfaces that moved: - Behaviour: which file a bare name runs in the Shell, so `program_path` can name another file for the same configuration. With an `[agent.filesystem] exec` entry and a `[tool]` with fixed arguments on another file of that name, a bare name now selects the tool and can be refused. - Startup disclosure: two new line forms. - Vendored Shell: `Kernel::host_program`, `os::HostPrograms`, `VfsKernel::host_programs`, `ShellBuilder::host_programs`, and `exec::implements_program`. `crates/shell/UPSTREAM.md` records the divergence. The issue proposed the table label as the name. The label was rejected because it makes a label such as `brew_git` a callable name, and `[tool.python]` on `python3` would change what `python` runs. A new `[tool]` field was rejected because it adds a key to a frozen table. The entry `a-host-binary-resolves-on-the-operator-path` in `docs/design/decisions.md` is not rewritten in this commit, because that needs the maintainer's decision first. ## Tests - `declared_host_programs.rs` (vendored Shell): a declared name runs its file and keeps the typed name; an undeclared name uses `PATH`; a spelling with `/` ignores the declarations; builtins, Shell commands, and functions keep precedence; a gone file is not found and `PATH` is not used. - `run::commands::tests`: a tool answers to its command's file name; two files under one name stay on `PATH`; a grammar on another program name declares nothing; a grammar `program` that another file answers to stays on `PATH`; Shell names are not declared; a linked command keeps its link. - `command::run::tests::startup_names_the_file_each_bare_name_runs` pins the disclosure. - `tool_grammars.rs`: `a_bare_name_runs_the_tool_that_declares_it_when_another_file_is_first_on_path` and `without_a_grammar_a_bare_name_runs_its_tool_under_shell_spawn` run a real box with a decoy `git` first on `PATH`. - Each new pin fails with its defect restored. - Linux aarch64: the `strands-shell` suite passes, and clippy and fmt are clean. The `strands-box` suite passes except `runtime_ignores_workspace_and_private_generated_schema_artifacts`, which times out in its binary on this host on `main` too. - macOS: the targeted tests above, including both end-to-end tests, and the `strands-box` suite. - macOS 27.0.1 (mac2.metal): with `[tool.git]` on Xcode's git and `/usr/bin` first on `PATH`, `main` denies `shell:spawn` on `/usr/bin/git`, and this change prints `git version 2.50.1 (Apple Git-155)`. On macOS, two `strands-box` unit tests fail on `main` too: `an_incomplete_scan_reports_its_cause_without_claiming_to_find_a_command` and `cancelling_before_the_launch_gate_preserves_the_signal_exit`. - The containment suite was not run to completion on Linux, because its harness writes into `/usr/bin`, which this host does not allow. CI runs it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
I learned that on macOS, binaries in
/usr/binlikegit,make, etc share the same underneath launcher file (named xcrun). This is a problem because Box treated a git grammar as applying to that whole file. That means, every tool in/usr/binlooked the same to Box. This PR makes the grammar apply only to the declared command name. I also updated the docs: because another name now goes through shell:spawn, permits should match both the program name and its path.I checked this on Linux, and the policy tests and Box grammar tests passed. I deliberately broke the behavior, and the tests caught it. Some Box tests still fail because of this devbox's mount setup. I didn't test the real macOS /usr/bin/git locally; CI covers that.
Related Issues
#38
Type of Change
Bug fix
Testing
On Linux, the policy crate tests passed with and without all features. Clippy shows no new warnings, and formatting is clean. The new tests show that a grammar on a file with several names binds only the declared name, and that each other name decides exactly as a plain
shell:spawn. I put the old refusal back on purpose and 7 tests caught it. I also made the replaced-file refusal cover every name, and 4 tests caught that. In the box crate, every grammar and binding test passed. The tests that failed on this devbox fail because of its mount table, and they are not related to this change. I didn't run the macOS test against the real/usr/bin/gitlocally. CI runs it.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.