Repository navigation
fix(box): run a tool's own file for the bare name the agent types - #388
Conversation
## 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.
|
Assessment: Comment The seam is small and placed correctly: it comes after the builtin, command, and function checks and before the Review details
Checks that held (one line each):
The decoy-first-on- |
…in a fixed-argument tool's claim
|
Thanks. In 7acac7f, |
|
Assessment: Comment (re-review of 7acac7f) 7acac7f addresses both earlier threads and adds the fixed-argument test I asked for. The new Cases traced through
|
|
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 Checks that held:
|
|
Assessment: Comment (re-review of 7f622cf) 7f622cf keys bare-name resolution on the canonical command path instead of Cases traced through
|
|
Assessment: Comment (re-review of 0b2404b) 0b2404b changes only documentation. It rewrites the Checks that held:
|
…e rule's exceptions
|
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 Checks that held:
|
…am of a tool's name
|
Assessment: Comment (re-review of 310cc51) 310cc51 changes only the last sentence of the Checks that held:
|
kevin-orellana
left a comment
There was a problem hiding this comment.
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?
Description
When the agent types
gitin the box's shell, Box looks it up on thePATHof therunprocess and then picks the[tool]whose file it found. If a tool's file isn't the firstgiton thatPATH, the agent can't reach it by name. That's what breaksgiton 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 anyPATHlookup. 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),PATHstill 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'snpm-cli.js, keeps the existing startupPATHcheck and usesPATHas 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 toPATH. It doesn't grant anything new: the spawn still needs ashell:spawnpermit or a grammar action.runprints 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/binfirst onPATH), the issue's exact config gets denied on main, and with this changegitruns Xcode's git. The new tests run a real box with a decoygitfirst onPATH, 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:
brew_gitwould become a command and[tool.python]onpython3would change whatpythonruns. 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.[tool.cargo_fmt] command = ["/usr/bin/cargo", "fmt"], a barecargo buildis refused rather than reaching a differentcargothrough anexecentry. That's what already happens today when both point at the samecargo, 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
PATHworkaround 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.
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.