Skip to content

fix(box): run a tool's own file for the bare name the agent types - #388

Merged
ferdingler merged 7 commits into
mainfrom
feature/declared-tool-bare-name
Nov 10, 2026
Merged

ferdingler merged 7 commits into
mainfrom
feature/declared-tool-bare-name

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Description

When the agent types git in the box's shell, Box looks it up on the PATH of the run process and then picks the [tool] whose file it found. If a tool's file isn't the first git on that PATH, the agent can't reach it by name. That's what breaks git on macOS with full Xcode: Box CLI's git pack points at Xcode's own git, but /usr/bin/git (Apple's stub) comes first. So the command is judged as a spawn of the stub and denied. The same thing happens with Homebrew git behind /usr/bin.

Now a bare name that a [tool] answers to runs that tool's file, the one Box already opened and checked at startup, before any PATH lookup. A tool answers to the file name of its command, not to its table label. Names the shell implements itself (cat, python3, sh, ...) still run the shell's own version. When two tools whose commands resolve to different paths share a name (hard links at two paths count as two), PATH still decides if it finds one of them; if it finds neither (like the Xcode stub), the tool whose label is the name wins. A grammar whose command names a link's target, like npm's npm-cli.js, keeps the existing startup PATH check and uses PATH as today; the docs say to point the command at a link named after the program if you want it pinned. If a tool's file disappears, the name is "not found" rather than quietly falling back to PATH. It doesn't grant anything new: the spawn still needs a shell:spawn permit or a grammar action. run prints one line per name saying which file it runs. This touches the vendored shell (a small hook so Box can declare these names), and that's recorded in its upstream notes.

On my Mac (macOS 27, Xcode installed, /usr/bin first on PATH), the issue's exact config gets denied on main, and with this change git runs Xcode's git. The new tests run a real box with a decoy git first on PATH, on Linux and macOS. I broke each new guard on purpose, and its test caught it. The full suites pass on both, apart from three tests that fail the same way on main on those hosts. The Linux containment suite I couldn't run locally, so CI covers it.

Decisions I made on this:

  • A tool answers to the file name of its command, not its table label. With labels, brew_git would become a command and [tool.python] on python3 would change what python runs. For Box CLI packs the two are the same, because each tool is named after its program. The "host binary resolves on the operator's PATH" decision entry now says this.
  • A tool with fixed arguments claims its name too (there's a test for it). With [tool.cargo_fmt] command = ["/usr/bin/cargo", "fmt"], a bare cargo build is refused rather than reaching a different cargo through an exec entry. That's what already happens today when both point at the same cargo, and leaving these tools out would keep the bug for them. The shell docs say so.

Once this lands, strands-agents/staging-boxy#365 can drop its PATH workaround and just point the git pack at Xcode's git.

Related Issues

Fixes #385

Type of Change

Bug fix

Testing

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

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

## 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.
Comment thread docs/user/tool-grammars.md Resolved
Comment thread crates/box/src/run/commands.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment

The seam is small and placed correctly: it comes after the builtin, command, and function checks and before the PATH walk. Policy still judges every spawn, and select_tool still checks the opened identity. I found no correctness defect in the main path. The two inline notes are about scope. Some configurations that #385 names still depend on PATH: grammars whose command[0] is the link's target, and two tools that answer to the same name.

Review details
  • Approval gate (root AGENTS.md, "strands-box is interface-frozen"): Which file a bare name runs, and so the program_path a permit sees, is behaviour that operators can observe. So is the change where a tool with fixed arguments claims its name. Both need an explicit maintainer decision before merge, as you already ask. After that decision, docs/design/shell.md still cites a-host-binary-resolves-on-the-operator-path, which this change contradicts, so that entry needs its rewrite. A test that pins the fixed-argument refusal (cargo build with [tool.cargo_fmt]) would also lock in the behaviour that shell.md now documents.
  • Verified locally (Linux): declared_host_programs passes 5/5, and the run::commands tests plus startup_names_the_file_each_bare_name_runs pass. The two new tool_grammars tests skip here because the namespace launcher is unusable. CI enables user namespaces, so CI runs them.

Checks that held (one line each):

  • Builtins, Shell commands, functions, sh/lash, and python/python3 keep precedence (runtime order plus the implements_program filter).
  • A name with a / and an alias that expands to a path ignore the map. xargs and find -exec go back through the same admit.
  • Policy is still the only authorizer: a declared name still raises shell:spawn or the grammar action. Removing or replacing a tool's file still refuses rather than falling back to PATH.
  • CallKernel is the only kernel wrapper, and it forwards host_program.
  • A symlinked command keeps its link as argv[0]. Rustup-style links to one file each keep their own name, and select_tool breaks the tie by the called name.
  • The vendored divergence is recorded in UPSTREAM.md, and the stdio MCP start path is unchanged.

The decoy-first-on-PATH integration tests reproduce the reported bug well.

@ferdingler

Copy link
Copy Markdown
Collaborator Author

Thanks. In 7acac7f, a_tool_with_fixed_arguments_claims_its_bare_name_and_refuses_other_arguments runs a real box with [tool.cargo_fmt] and a decoy cargo first on PATH. cargo fmt runs, and cargo build is refused because no table matches, which is the behaviour shell.md documents. The a-host-binary-resolves-on-the-operator-path rewrite waits for the maintainer decision this PR asks for, as you say.

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

Copy link
Copy Markdown

Assessment: Comment (re-review of 7acac7f)

7acac7f addresses both earlier threads and adds the fixed-argument test I asked for. The new label_choice tie-break gives the right result in every case I traced. The one remaining note is non-blocking: the startup line for a label-settled name, posted inline. The maintainer's approval for this interface change (root AGENTS.md) and the decision-record rewrite are still open, as before.

Cases traced through label_choice
  • Xcode stub first, plus [tool.git] (Xcode) and [tool.brew_git]: picks [tool.git]. This fixes A bare name should run the [tool] declared for it, not the first match on the host PATH #385 for the config that tool-grammars.md shows.
  • Homebrew first: PATH finds a claimant, so the name stays shared. Today's behaviour and pinned permits are unchanged.
  • No git on PATH: the label table runs, where main reports not found.
  • A link-target grammar (npm-cli.js, declares = false): never chosen by label, so the fix(box): bind a tool grammar to how box cli binds tools #358 check still holds.
  • PATH reaches a claimant through a symlink: the identity compare follows the link, so the name stays shared.
  • Two tables can't both carry the label, and a label table whose grammar names another program is not among the claimants.

Checks that held:

  • find_on and host_search_path() match the Shell's runtime host_path_lookup and the PATH it reads, so the startup decision and the runtime fallback agree.
  • bare_names gets the same PATH in the disclosure and in BrokerHost::start.
  • a_bare_name_..._refuses_other_arguments pins the documented cargo build refusal (status 126 plus the no-match message).
  • Verified locally: 21/21 run::commands and disclosure unit tests pass, including the_label_breaks_a_tie_that_path_does_not_settle.

The fix is narrow: it keeps the brew-first configs that work today unchanged.

@github-actions

Copy link
Copy Markdown

Assessment: Comment (re-review of eafe2f3)

eafe2f3 resolves the last open note, and the change adds no new defect. What still blocks merge is unchanged: the maintainer's approval for this interface change (root AGENTS.md), followed by the a-host-binary-resolves-on-the-operator-path decision-record rewrite.

Checks that held:

  • passed_over is filled only when the label decides; when every table runs one file, it stays empty.
  • declared lists exactly the tables whose identity matches the chosen file, including tables that don't declare the name but run that file.
  • No other code builds BareNames or reads passed_over. programs() still reads only declared, so the Shell's lookup map is unchanged.
  • The new line escapes the name, and its [tool.<name>] matches the label that label_choice requires.
  • Verified locally: 24/24 run::commands and command::run unit tests pass, and cargo fmt --check is clean.

@github-actions

Copy link
Copy Markdown

Assessment: Comment (re-review of 7f622cf)

7f622cf keys bare-name resolution on the canonical command path instead of (dev, ino). This matches how select_tool_with_commands chooses a tool (command.path() != invoked), and I found no new defect. The open items are the same as before: the maintainer's approval for this interface change (root AGENTS.md), then the a-host-binary-resolves-on-the-operator-path decision-record rewrite.

Cases traced through bare_names / label_choice
  • Hard links at developer/git and project/git, with project first on PATH: the name is shared, and the Shell runs project/git, which selects [tool.project_git]. Under main's identity compare, the startup line listed both tables for developer/git, but only [tool.git] would have been selected.
  • The same hard links, with the stub first: [tool.git] is declared, and [tool.project_git] is listed as passed over.
  • Two spellings that resolve to one file through symlinks (/opt/homebrew/bin/git and the Cellar path): granted_path() is canonical (canonicalize_existing), so they compare equal and the name is declared as before.
  • PATH reaches a configured tool through a symlink: find_on(...).canonicalize() equals the canonical command.path, so the name stays shared, as before.
  • PATH finds a third, unconfigured hard link: before this commit, no table would have selected it at spawn. Now the label table runs it, which is an improvement.
  • PATH finds a dangling link, or nothing: canonicalize fails, and the label decides, as before.

Checks that held:

  • Both sides of every path compare are canonical, so a symlink spelling does not split a name.
  • The startup line's "running" tables now equal the tables a spawn of that file can select.
  • Verified locally: 26/26 run::commands, command::run, and run::hosted selection unit tests pass, and cargo fmt --check is clean. When the two compares are reverted to identity, hard_links_at_two_paths_keep_the_table_that_path_selects fails, so the test guards the change.

@github-actions

Copy link
Copy Markdown

Assessment: Comment (re-review of 0b2404b)

0b2404b changes only documentation. It rewrites the a-host-binary-resolves-on-the-operator-path entry, which was the open follow-up, and it updates the link text in docs/design/shell.md. I left one inline note: the rewrite drops the canonical-identity guarantee, and its first claim is broader than what the code does. Merge still waits on the maintainer's approval for this interface change (root AGENTS.md).

Checks that held:

  • The anchor a-host-binary-resolves-on-the-operator-path is unchanged, so the code and doc links still resolve (kd: "Keep the anchor unchanged").
  • The three test names cited in the entry exist: the_longest_matching_command_prefix_selects_the_tool (run/hosted.rs), and the two tool_grammars.rs integration tests.
  • The behaviour the entry states agrees with bare_names, label_choice, and select_tool_with_commands at this head: the path tie-break, the label fallback, and the refusal when a tool has fixed arguments.
  • The rejected alternative (the label as the name) is given in one sentence, as kd asks.
  • No line in the new entry is longer than 100 characters, and no code changed since 7f622cf.

Comment thread docs/design/decisions.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment (re-review of 8ef2e39)

8ef2e39 resolves my earlier inline note. The canonical-identity guarantee is restored word for word, and the name rule now states the grammar and Shell-implemented exceptions. The entry is also shorter. I left one new inline note: the rewritten last sentence states the cost as a refusal, but in the common case the bare name runs the tool's file. Merge still waits on the maintainer's approval for this interface change (root AGENTS.md).

Checks that held:

  • The exceptions now match bare_names: bound_name and called_name must agree, and implements_program names are skipped.
  • The restored identity sentence is still true at this head (declared_program → HostProgram::bound; no re-resolution in select_tool_with_commands).
  • The anchor is unchanged, and both cited test names exist (run/hosted.rs, tests/tool_grammars.rs).
  • Only docs/design/decisions.md changed since 0b2404b, and no new line is longer than 100 characters.

Comment thread docs/design/decisions.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment (re-review of 310cc51)

310cc51 changes only the last sentence of the a-host-binary-resolves-on-the-operator-path entry, and it resolves my previous inline note. I have no new findings. Merge still waits on the maintainer's approval for this interface change (root AGENTS.md).

Checks that held:

  • The cost now matches the behaviour: a bare name runs the tool's file, as a_bare_name_runs_the_tool_that_declares_it_when_another_file_is_first_on_path shows, or it is refused when no table matches the arguments. It agrees with docs/user/shell.md ("no longer reaches").
  • The rest of the entry (canonical-identity guarantee, exceptions to the name rule, anchor, cited tests) is unchanged from 8ef2e39.
  • No code changed, and no line is longer than 100 characters.

@kevin-orellana kevin-orellana left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. I accept the documented compatibility change: a configured tool, including one with fixed leading arguments, claims its executable name. A second installation needs its own tool declaration or must be called by its full path.

Compared this revision with d9346bf0d281153ea7dc6338ad1f0b7e122be687 on Linux: 17 routing and argument checks plus five actual Cargo invocations per revision, including an offline library build. Ordinary subcommands and flags, multiple fixed-prefix declarations, and general fallback declarations worked. The separately permitted second Cargo installation ran on the base revision and was refused here; its explicit path worked on both. That compatibility tradeoff is accepted. The hosted Linux and macOS unit and deterministic containment checks also passed.

Nonblocking follow-up: in a standalone Shell probe, a same-named executable script in the in-memory filesystem ran before the declared-program lookup. The corresponding Box controls with direct filesystem bindings passed. Could we add this case and either preserve the documented precedence or narrow the standalone API's promise?

@ferdingler
ferdingler merged commit 4adaa04 into main Nov 10, 2026
21 of 22 checks passed
@ferdingler
ferdingler deleted the feature/declared-tool-bare-name branch November 10, 2026 20:52
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.

A bare name should run the [tool] declared for it, not the first match on the host PATH

2 participants