Skip to content

fix(shell): give the hosted Shell each route's phantom - #431

Merged
yesyayen merged 1 commit into
mainfrom
feature/shell-phantoms
Nov 12, 2026
Merged

yesyayen merged 1 commit into
mainfrom
feature/shell-phantoms

Conversation

@yesyayen

Copy link
Copy Markdown
Contributor

Description

A command that the agent sends to the Shell could not use a credential route. The Shell got no placeholder, so $NAME was empty there, and the gateway refused the request.

Example box: an env:// route, and an agent that runs curl through its zsh alias. Claude Code's Bash tool sends every command this way.

[egress.echo]
destinations = ["postman-echo.com"]
secret.ref = "env://DEMO_TOKEN"
printf '1 agent: DEMO_TOKEN=%s\n' "$DEMO_TOKEN"
zsh -lc 'printf "2 shell: DEMO_TOKEN=%s\n" "$DEMO_TOKEN"'
zsh -lc 'curl -sS -o /dev/null -H "Authorization: Bearer $DEMO_TOKEN" https://postman-echo.com/get; echo "3 shell curl rc=$?"'
zsh -lc 'curl -sS -H "Authorization: Bearer $DEMO_TOKEN" https://postman-echo.com/get | jq -c "{authorization: .headers.authorization}"'

Before, on macOS with main (61ade09):

1 agent: DEMO_TOKEN=strands_box_81b5717ceecea2cb42a91f8a3a31e9ba35db52ce4ce727f788c6df296f69e3d1
2 shell: DEMO_TOKEN=
3 shell curl rc=1
curl: blocked by egress control
curl: blocked by egress control

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, and USER.

The fix: Box gives each new Shell the same placeholders that the sandboxes get, before its own HOME, PWD, and USER, 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:

1 agent: DEMO_TOKEN=strands_box_d7d141942899a408fe64be0ae62dcd797942e9a689f9fba10a98c63df1d534e6
2 shell: DEMO_TOKEN=strands_box_d7d141942899a408fe64be0ae62dcd797942e9a689f9fba10a98c63df1d534e6
3 shell curl rc=0
{"authorization":"Bearer [REDACTED]"}

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. env in the Shell lists those names too. Python (Monty) still refuses os.getenv, as before. If [agent] env sets 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 on main (shell= is empty).

  • Changed: the_shell_cannot_read_the_daemons_resolved_secrets now also checks that $NAME and Lua os.getenv give 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, and a_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 on main.

  • Linux x86_64 (Amazon Linux 2023 container), Rust 1.98.1: clippy with the just clippy flags is 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, 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, 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

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.
@yesyayen
yesyayen marked this pull request as ready for review November 12, 2026 19:46
@github-actions

Copy link
Copy Markdown

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 attachment.phantoms, the same list the sandboxes get, through environment::compose. The Shell then sets its own names last. The one open item is a process item, not a code item. Root AGENTS.md lists "the composed environment" as a frozen surface. It also says "Record an entry in docs/design/decisions.md only after the user decides it." This PR does both. It says so and asks for confirmation, so it is disclosed. A maintainer still needs to approve it explicitly. After that approval, I see nothing that blocks merge.

Assumptions and rules checked (all held)
  • Every route reaches the Shell: the Shell gets env:// phantoms, aws:// signing placeholders, and backend strip phantoms (merge_workload_environment). The aws:// placeholders repeat once per signed route. set_env is idempotent, so the repeats do no harm.
  • A phantom cannot displace the Shell's names: checked_provisioned_name refuses HOME/PATH (composed_over) and every name in reserved_workload_environment. The Shell sets PWD/USER after the phantoms. The unit test covers this.
  • Input that was valid before this change: a box with no route still gives exactly HOME PATH PWD USER. a_new_shell_holds_each_provisioned_variable_and_nothing_else checks this with a full-equality assertion, and SH-ENV still checks it.
  • No gateway (egress: None): the Shell holds phantoms, but its network stays disabled. The phantoms are inert, and nothing new can reach the network.
  • Tools spawned from the Shell: tool_spawner builds the tool's environment from Attachment, not from the Shell's environment. That behavior is unchanged.
  • Other places that build a Shell: the only production Shell::builder() call is ShellSpec::build. The one in kernel.rs is test-only.
  • crates/box/AGENTS.md "box-owned values go last": the Shell keeps this rule.
  • Real secret never in the Shell: it holds only ProvisionedVariable values. Both integration tests assert that REAL_SECRET is absent.
  • I ran the three new host.rs unit tests on Linux, and they pass.

There is no end-to-end test of a Shell curl whose phantom the gateway swaps for the real secret. the_shims_shell_has_no_network_path notes that the SSRF floor blocks the loopback a local upstream would bind. So the macOS run in the PR description is the evidence for that path. That is acceptable here.

The PR description and before/after reproduction made this easy to verify.

@yesyayen
yesyayen merged commit 7f07645 into main Nov 12, 2026
31 of 35 checks passed
@yesyayen
yesyayen deleted the feature/shell-phantoms branch November 12, 2026 20:41
ferdingler added a commit that referenced this pull request Nov 13, 2026
…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.
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.

Credential placeholder is available to the agent but missing from the brokered Shell: expected behavior?

2 participants