Repository navigation
fix(shell): give the hosted Shell each route's phantom - #431
Conversation
## Problem Every contained process gets the phantom of each credential route: the agent, each tool, and each stdio MCP server. The hosted Shell did not. `ShellSpec::build_on` set only `PWD`, `HOME`, and `USER`, beside the Shell's default `PATH`. A command that the agent sends through its shell alias expanded the route's variable to an empty string. So `curl -H "Authorization: Bearer $NAME"` sent no phantom, and the gateway refused the request under the default `inject = "phantom"`. Claude Code's Bash tool sends every command this way. Reported in #39. ## Solution `HostedBox::open` passes `Attachment.phantoms`, the list that every sandbox gets, to `BrokerHost::start`. `ShellSpec` stores it as `phantoms`. `ShellSpec::build_on` sets each variable on the new Shell before `PWD`, `HOME`, and `USER`, the order that `environment::compose` keeps for a sandbox, so a phantom cannot displace the Shell's own names. The Shell holds phantoms and the public `aws://` placeholder keys, never a resolved secret. Interface: the hosted Shell's environment gains each provisioned name. This is a change to the composed environment, which the interface freeze covers. A maintainer confirmed this behavior on #39. The broker protocol, the stored record, `box.toml`, and the tool and MCP environments do not change. Docs: `docs/user/shell.md`, `docs/user/egress.md`, `docs/user/config.md`, `docs/design/egress.md`, `docs/design/credentials.md`, and the decision entry `the-box-is-the-credential-boundary` name the hosted Shell. The `SH-ENV` case in `test-integ` now says that its exact environment holds for a box with no egress route. ## Tests - `box_credentials.rs::the_shell_holds_the_workloads_phantom_and_never_the_secret`: the workload and the Shell print the same phantom, and the real secret appears in neither. On `main` it fails with `shell=` empty. - `box_credentials.rs::the_shell_cannot_read_the_daemons_resolved_secrets`: also asserts that `$NAME` and Lua `os.getenv` give the phantom. The real-secret assertion is unchanged. - `host.rs::a_new_shell_holds_each_provisioned_variable_and_nothing_else` and `each_program_starts_from_the_provisioned_value` fail without the `set_env` loop. - `host.rs::a_provisioned_variable_cannot_displace_the_shells_own_names` fails when the loop runs after the Shell's own names. - macOS 26 arm64, Rust 1.96.0, `cargo test --workspace --all-features`: 5097 passed, 2 failed, 19 ignored. The two failures, `cancelling_before_the_launch_gate_preserves_the_signal_exit` and `a_port_with_no_listener_is_not_ready`, pass alone on this branch and on `main`. `cargo fmt --all --check` and the site manifest test pass. - Linux x86_64 (Amazon Linux 2023 container), Rust 1.98.1: `just clippy` flags, clean. `cargo test --workspace --all-features`: 5468 passed, 11 failed, the same 11 as `main` in that container. Tests that start a box skip on x86_64. - macOS, a box with an `env://` route to postman-echo.com: a Shell `curl -H "Authorization: Bearer $DEMO_TOKEN"` gets `curl: blocked by egress control` on `main` and `{"authorization":"Bearer [REDACTED]"}` on this branch. - Not run: Linux aarch64 and `test-integ`, which CI runs. Clippy on macOS: Rust 1.96.0 reports lints in unchanged code that 1.98.1 does not.
|
Assessment: Comment. I found no code defects. A maintainer must approve the frozen-surface change before merge. The fix is narrow and correct. Each Shell gets Assumptions and rules checked (all held)
There is no end-to-end test of a Shell The PR description and before/after reproduction made this easy to verify. |
…against the upstream Shell The vendored Shell files that #397 changed are deleted here. #397's Shell tests move to crates/shell/tests/main_shell_semantics.rs and the broker tests, and its two Lua stdin tests move to the broker. The tests for #397's Shell fixes fail until the upstream Shell fixes land.
Description
A command that the agent sends to the Shell could not use a credential route. The Shell got no placeholder, so
$NAMEwas empty there, and the gateway refused the request.Example box: an
env://route, and an agent that runscurlthrough itszshalias. Claude Code's Bash tool sends every command this way.Before, on macOS with
main(61ade09):Why: the agent, each tool, and each stdio MCP server get every route's placeholder. The Shell runs in the box's trusted process, and Box built it with only
HOME,PATH,PWD, andUSER.The fix: Box gives each new Shell the same placeholders that the sandboxes get, before its own
HOME,PWD, andUSER, so a placeholder can't replace those. The Shell still never holds the real secret. The broker protocol, the stored record,box.toml, and the tool and MCP environments don't change.After, with this branch:
The gateway put the real token in place of the placeholder. The echo server sent it back, and the gateway removed it from the response.
What changes for an operator: a Shell command now sees each route's placeholder, the same value the agent sees.
envin the Shell lists those names too. Python (Monty) still refusesos.getenv, as before. If[agent] envsets a route's variable, the agent sees the declared value and the Shell sees the placeholder, as a tool does.Decision: the box is the credential boundary now names the hosted Shell. Please confirm this change to the Shell's environment.
Related Issues
Fixes #39
Type of Change
Bug fix
Testing
New:
the_shell_holds_the_workloads_phantom_and_never_the_secret. The agent and the Shell print the same placeholder, and the real secret appears in neither. It fails onmain(shell=is empty).Changed:
the_shell_cannot_read_the_daemons_resolved_secretsnow also checks that$NAMEand Luaos.getenvgive the placeholder. Its real-secret check is unchanged.New unit tests in
host.rs:a_new_shell_holds_each_provisioned_variable_and_nothing_else,each_program_starts_from_the_provisioned_value, anda_provisioned_variable_cannot_displace_the_shells_own_names. The first two fail without the fix. The third fails when the placeholders are set after the Shell's own names.macOS 26 arm64, Rust 1.96.0,
cargo test --workspace --all-features: 5097 passed, 2 failed, 19 ignored. The two failures (cancelling_before_the_launch_gate_preserves_the_signal_exit,a_port_with_no_listener_is_not_ready) pass when run alone, on this branch and onmain.Linux x86_64 (Amazon Linux 2023 container), Rust 1.98.1: clippy with the
just clippyflags is clean.cargo test --workspace --all-features: 5468 passed, 11 failed, the same 11 asmainin that container. Tests that start a box skip on x86_64, so CI's Linux ARM64 run covers them.Not run: the deterministic containment suite (
test-integ), which CI runs. Clippy on macOS, because Rust 1.96.0 reports lints in unchanged code.I ran the relevant suites (
just check, orcargo test --workspace --all-features)If I touched Rust, I ran
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.