Skip to content

fix(policy): decide an undeclared name of a grammar-bound file as shell:spawn - #352

Merged
ferdingler merged 3 commits into
mainfrom
feature/tool-grammars-multiname
Nov 7, 2026
Merged

ferdingler merged 3 commits into
mainfrom
feature/tool-grammars-multiname

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Description

I learned that on macOS, binaries in /usr/bin like git, 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/bin looked 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/git locally. CI runs it.

  • 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.

…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.
Comment thread crates/box/src/run/hosted.rs Resolved
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Assessment: Request Changes

The macOS fix is correct for the names the host installs. The one problem is in the inline comment: removing Starter also removed the only way to tell an MCP server's start from the agent's spawn of the same file under the same name. So the grammar can be skipped, and pinning program and program_path cannot prevent it.

Assumptions and rules checked that held
  • macOS make, a hard link of a bound /usr/bin/git called by its bare name, gets coverage = None, so shell:spawn decides it as intended.
  • git on the bound file still parses with the git grammar, as it did before this change.
  • An agent symlink ./make -> /usr/bin/git does not match a permit pinned on program == "make" && program_path == "/usr/bin/make", because program_path resolves to /usr/bin/git.
  • A mise shim python with a cargo grammar on the shim is a shell:spawn, and the shim picks the tool by name, so this is correct.
  • A replaced bound file is still refused under its bound name, and a bare bound name whose file is gone is still refused.
  • The policy crate's pub use set is unchanged, because Starter and UndeclaredName were pub(crate).

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

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
  • Agent spawn of a bound file under a name that only a server declares: refused for the server's path, for an agent-made link with the same name, and for the bare name. I tested this with a start permit pinned on both fields.
  • Server start under that same name: still a shell:spawn through Starter::Server.
  • macOS make via the bound /usr/bin/git (nothing declares that name): still shell:spawn.
  • A name that a [tool] also declares on the same file: not refused, so the operator's permit decides it.
  • A server on a file that no grammar binds: not refused, because of the binds_file guard.
  • git on the bound file: still parsed by the grammar.
  • Replaced bound files and gone bare names: still refused.
  • bind_tool_grammars calls declare_server for every resolvable stdio server, and host.rs starts servers only through into_server_start_handle.
  • Root AGENTS.md security-test rule: the agent-refusal assertion is restored.
  • Policy crate pub use set: unchanged, since Starter and ServerName are pub(crate).
  • Policy grammar unit tests (44 pass) and hosted.rs an_mcp_server* tests: pass.

Comment thread crates/policy/src/grammar/bindings.rs Resolved
@ferdingler
ferdingler merged commit 2aa281d into main Nov 7, 2026
28 of 29 checks passed
@ferdingler
ferdingler deleted the feature/tool-grammars-multiname branch November 7, 2026 00:58
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.
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.

2 participants