Skip to content

fix(mcp)!: preserve ordinary program execution beside MCP aliases - #357

Merged
notowen333 merged 5 commits into
strands-agents:mainfrom
notowen333:codex/mcp-alias-fallback
Nov 10, 2026
Merged

notowen333 merged 5 commits into
strands-agents:mainfrom
notowen333:codex/mcp-alias-fallback

Conversation

@notowen333

@notowen333 notowen333 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

Declaring an MCP server through npx currently blocks unrelated calls such as npx --version. This change lets unmatched commands run the ordinary executable inside the agent's existing sandbox.

Examples

Suppose the declared command is npx -y [email protected], with exact argument matching. Calls through Box's npx alias behave as follows:

Command Before After
npx --version Refused Runs ordinary npx, if the agent's grants allow it
npx -y [email protected] Starts the declared MCP server after policy approval Unchanged
npx -y [email protected] Refused Attempts ordinary execution; records strands.box.mcp.unmatched

Policy denials, ambiguous matches, and broker errors still fail closed. They never trigger fallback.

Trade-off

A mistyped server command can now run without Box's MCP tool checks. It receives only the agent's grants and environment, with no declared-server secrets or extra grants.

Operators can find these mismatches through the informational strands.box.mcp.unmatched log in scope strands-box.mcp. It records the program, redacted arguments, and available request correlation. It carries no policy verdict or ordinary execution outcome. Default targets and targets selecting logs receive it. See the approved decision.

Why the !?

Previously, npx --version was rejected as an MCP launch. It now gets a response telling the alias to run the real npx. A denied server launch still gets an error.

This changes the broker protocol from version 7 to 8. Old and new binaries cannot communicate, so the broker and alias must be upgraded together.

Execution compatibility

  • Existing stream completion behavior is preserved; version or program-ID mismatches exit 125.
  • Fallback requires scripts to have a shebang; unexpected PATH lookup errors stop the search. Missing executables report 127; execution refusals report 126. On Linux, a missing grant can make an executable invisible.

Related Issues

Fixes #354

Type of Change

Bug fix; breaking internal protocol change.

Testing

  • Telemetry update, macOS ARM64: 1,015 tests passed; one existing HTTPS-dependent test was ignored. Five compilable mutations failed at the intended assertions. Clippy, formatting, the build without default features, site-manifest checks, and independent review passed. Linux was not rerun for this telemetry change.

  • Earlier fallback validation, Linux: all 27 affected tests pass (run), including fallback containment and secret isolation.

  • Earlier broad validation, macOS: 1,265 passed, 5 existing ignored. One tool_grammars test fails with exit 137 instead of 1; the same failure reproduces on clean base 3eda3e2.

  • Package build, Clippy, formatting, no-default-features build, and site-manifest checks pass. Five mutation checks caught the intended defects.

  • Full workspace and live-agent checks were not run.

  • 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

A declared MCP server installs an alias for its launcher. This alias also
intercepts ordinary calls such as npx --version. A call that does not match
the server command is refused, so the declaration hides the ordinary program.

## Solution

Return a distinct non-match from MCP admission. The alias then searches the
agent's PATH, skips its own directory and image, and replaces itself with
the ordinary executable inside the existing agent sandbox.

Add McpReady and McpUnmatched responses and advance the broker protocol from
version 7 to 8. The broker and alias must be upgraded together. Wait for the
response before reading stdin, and send readiness before relaying server output.
Keep policy denials, invalid expansions, ambiguous matches, and protocol errors
as failures. Preserve matched server authorization and add no sandbox grants.

Document ordinary fallback, the mistyped-command behavior, and exit statuses.

## Tests

unmatched_aliases_preserve_process_inputs_and_skip_their_own_image proves
argument, input, environment, working-directory, output, and exit preservation
for npx, uvx, and node. It fails against the previous alias implementation.
fallback_retains_signal_termination and
fallback_closes_inherited_and_broker_descriptors check process termination
and descriptor closure.

only_a_valid_nonmatch_response_can_execute_fallback rejects invalid routes.
the_alias_waits_for_readiness_before_sending_input checks the input boundary.
an_mcp_route_that_never_answers_times_out checks the bounded routing wait.
ordinary_fallback_keeps_agent_grants_and_never_receives_server_secrets proves
the containment boundary with positive controls for matched server access.

The final macOS checks pass for all six fallback process tests, 19 MCP startup
tests, 37 alias unit tests, and four filesystem_modes tests. The latter caught
and now pin preservation of clean stream closure after MCP readiness.
The named broker and hosted lifecycle tests pass with readiness consumption.

Package build, clippy, formatting, the build without default features, and
site_manifest pass. Box has no new warnings. Dependency warnings are unchanged.
The doc-test gate has no examples. The example script builds successfully but
finds no remaining scripted examples. Documentation review passes.

The deterministic suite finishes green with 129 passed and 12 declared
Linux-only skips. An image-guard failure from an overlapping rebuild and an
elapsed-time failure under load both pass on isolated reruns.

tool_grammars::a_push_is_denied_until_a_test_exits_0_and_stays_allowed_after_a_restart
still fails because its fake cargo exits 137 instead of 1. The same named test
fails with identical output on unchanged base 3eda3e2. Leave this pre-existing
host failure outside this change. All other executed package tests pass after
the targeted fixes and reruns.
Five existing tests remain ignored: two live HTTPS fixtures, two long-running
stress tests, and the upstream shell append issue.
Native Linux tests have not run. Full cross-compilation is blocked by the
missing aarch64-linux-gnu-gcc toolchain on this Mac.
@notowen333 notowen333 changed the title Preserve ordinary program execution beside MCP aliases fix(mcp)!: preserve ordinary program execution beside MCP aliases Nov 6, 2026
@notowen333
notowen333 marked this pull request as ready for review November 6, 2026 23:14
Comment thread crates/box/src/bin/alias/fallback.rs Resolved
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Assessment: Comment (approve once the inline suggestion is addressed or declined)

Reviewed at 6064d2a. Fallback is correctly limited to an explicit broker non-match, and it runs in the caller's existing sandbox. I found one lookup difference (unset PATH), posted inline. Nothing blocks the merge.

Assumptions and rules checked that held
  • admit_server returns Ok(None) only when the program is declared, every server on it expands, and neither an exact nor a wildcard command matches. Ambiguous matches, unexpandable commands, and undeclared programs still return Err and are refused.
  • Only a well-formed McpUnmatched frame can reach fallback. Denials, version or program-ID mismatches, early exits, closed connections and stray frames all exit 125; only_a_valid_nonmatch_response_can_execute_fallback covers this.
  • "Policy is the only authorizer" and "a workload-named program runs only inside a sandbox" (root AGENTS.md): fallback execs inside the alias's own process, so it adds no grants and passes on no server credentials. absent_start_permit_refuses_the_server_and_it_never_runs is preserved.
  • PATH search skips the alias directory and any hard link or symlink to the alias image (by device/inode). Directories, EACCES/EPERM, a missing shebang (ENOEXEC) and an empty PATH (searched as the cwd) all behave like execvp.
  • Frozen surface: the broker protocol change is disclosed. The PR bumps PROTOCOL_VERSION from 7 to 8, cites a decision entry, and updates the user and design docs in the same change.
  • enforcement:mcp-unmatched records pass arguments through reportable(), so expanded values are redacted.
  • The new 60 s readiness wait is safe for matched servers: start_mcp_server contains no unbounded wait or credential fetch.
  • The McpReady-before-output ordering and the alias's wait for readiness before reading stdin are both pinned by tests.

The fallback tests pin both its process behaviour and its containment.

An unset PATH became an empty string, which split into one empty entry
and searched only the working directory. That directory is usually
agent-writable, so a planted program could replace the system one.
Fallback now uses /usr/bin:/bin for an absent or empty PATH, matching
ProcessConfig::search_path.
@github-actions

Copy link
Copy Markdown

Assessment: Approve

Re-reviewed at 66390a2, which adds the PATH fix (505f61a) and a merge of main that brings in #377 (absolute MCP executables). The earlier finding is fixed. I found nothing new, and nothing blocks the merge.

Checked since 6064d2a, all held
  • PATH fix: an unset or empty PATH now searches /usr/bin:/bin and never the working directory. Treating an empty PATH this way is stricter than execvp, which would search the working directory, and the user and design docs both say so. The new test passes.
  • Merge, code: protocol.rs, the alias binary and admission.rs merged without conflicts. Main's changes to host.rs (program() → executable() when starting a server, test frames /bin/sh → sh) don't touch the fallback logic. Every run::broker test passes; the only failure, in aliases, comes from a missing strands-box-contain-trampoline binary in this environment.
  • Merge, interaction with feat(mcp): support absolute executable commands #377: matching and the McpUnmatched record use program(), which is now the executable's filename, the same name the alias has in bin/. So:
    • An absolute-path server called with arguments that match no server falls back to the ordinary program of that filename on the agent's PATH, not to the configured absolute path.
    • A matched server whose absolute executable is missing goes through the start-failure path and exits 125 with no fallback. That keeps a_missing_absolute_command_never_falls_back_to_path true; that test returned early here because the namespace launcher isn't usable in this environment.
  • Merge, docs: the conflict resolutions in binaries.md, decisions.md, mcp.md and mcp-policy.md keep both the fallback wording and the absolute-path wording. The mcp-policy.md example for a harness that sets only npx now describes fallback instead of the old refusal.
  • Frozen surfaces: PROTOCOL_VERSION is still 8. Main changed nothing in the protocol, and the record version bump came from feat(mcp): support absolute executable commands #377, not from this PR.
  • Tests: mcp_alias_fallback passes all 8 tests locally.

Comment thread crates/box/src/run/broker/host.rs Resolved
Comment thread crates/box/src/bin/alias/fallback.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Approve

Re-reviewed at c4b2342. The only change since 66390a2 is that the unmatched-route record is no longer an enforcement_deny decision. It is now a separate mcp_unmatched signal, written in the strands-box.mcp scope with event name strands.box.mcp.unmatched. I found no problems, and nothing blocks the merge.

Checked at c4b2342, all held
  • Delivery by include:
    • With include absent, the target gets the record (default_targets_receive_unmatched_mcp_routes).
    • With include = ["logs"], it gets the record plus the agent's own logs.
    • With include = ["deny"] or ["permit"], it no longer gets the record. The verdict-only target in unmatched_mcp_routes_are_diagnostics_not_policy_decisions covers this. config.md and telemetry.md both say so, and the old deny-shaped record never shipped in a release.
    • When no target accepts the signal, the accepts check drops the record before any work.
  • Severity routing (telemetry AGENTS.md: "two signals may never share one"): the new signal uses Info3, which no other signal holds, and of_severity maps it back. no_two_signals_share_a_severity passes. Records the agent sends never reach this routing, so an agent log at severity 11 cannot be filed as this signal.
  • Spoofing: an agent can't fake the new scope. Any agent scope that starts with the reserved strands-box. prefix is renamed to agent-claimed:….
  • Spans: the span exporter (box_spans) skips strands-box.mcp, because the exporter only knows the policy and control scopes. So the record produces no span, as the docs say. strands.box.source = box and the box name still arrive, because they are attributes of the shared resource, not of each record.
  • Redaction: arguments still go through Subject::process with no argument marked literal. Plain flags are kept, values are redacted, and the length limits apply. The unit test and both runtime tests compare the whole process.command_args array.
  • Docs: the shipped jq recipes all filter by scope, so the new record can't mix into them. The renamed decision heading keeps its old anchor, and config.md keeps its old anchor. The telemetry AGENTS.md public-surface count and the signal and word expansion text are updated.
  • Tests and lint: all 84 strands-box-telemetry tests pass, as do the record::config::telemetry and run::broker::host library tests. Clippy reports no warnings in either touched crate. The runtime_mcp_start changes return early here because the namespace launcher isn't usable in this environment, so CI is where they actually run.

@notowen333
notowen333 merged commit c8cdbd1 into strands-agents:main Nov 10, 2026
16 checks passed
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.

An MCP server alias hides the agent's own program of the same name

2 participants