Repository navigation
feat(mcp): support absolute executable commands - #377
Conversation
## Problem Core uses the first MCP command element as both the launch target and the agent-facing alias. It rejects absolute paths, so an operator cannot select an executable outside PATH or choose one installation when another comes first. ## Solution Accept a bare name or an absolute path in the existing command array. Derive the alias from the requested filename and retain the full executable for launch and offline schema discovery. Preserve symlink invocation spelling. Apply the existing exact-command and wildcard collision rules to the derived alias. Relative paths, executable token expansion, and invalid or reserved alias names remain refused. Existing containment and permission rules remain in effect. Records with absolute MCP commands require version 28. Older records retain their existing version. Older Core builds refuse the new records before they can interpret absolute commands as alias paths. No TOML field, broker frame, policy attribute, or mechanism-crate public API is added. Document the approved choice at mcp-executable-filenames-name-their-aliases in docs/design/decisions.md and update the MCP, configuration, policy, alias, and record-version references. Boxy import and permission resolution remain a separate follow-up. ## Tests Core and containment helpers build with --locked --all-features. The final compiled Core library suite passes all 787 tests. runtime_mcp_start passes 20 tests and mcp_schema_generation passes 21 tests. Named coverage includes: - an_absolute_command_keeps_its_target_and_is_called_by_its_filename: the alias is the filename and the raw target remains available. - absolute_commands_share_an_alias_but_require_distinct_arguments and absolute_commands_keep_the_wildcard_overlap_rules: derived aliases retain the existing collision and matching rules. - absolute_commands_require_a_representable_filename and executable_paths_are_absolute_and_do_not_expand_tokens: invalid filenames, relative paths, and executable token expansion are refused. - absolute_mcp_commands_require_their_own_record_version: version 28 takes precedence over other features and absolute-command records with an older version are refused. - an_absolute_command_starts_its_selected_symlink_instead_of_a_path_decoy: the selected off-PATH server starts and retains its symlink invocation name. - a_missing_absolute_command_never_falls_back_to_path: the decoy never starts. - a_start_is_decided_on_the_canonical_program_and_its_arguments: the policy observes the basename command, canonical target, and configured arguments. - generate_schema_uses_an_absolute_command_instead_of_a_path_decoy: offline discovery selects the configured file. The new configuration regressions fail against the previous implementation. Core clippy reports no owned warnings. cargo fmt --all --check and the no-default-features build pass. Documentation and feature reviews find no remaining source or documentation defect. The full package test run stops during compilation with No space left on device. It does not have a passing verdict. The existing non-UTF-8 filesystem test reports its host prerequisite skip. Full workspace, Linux, deterministic containment, and exhaustive mutation checks remain unrun locally. This change opens as a draft for CI and human review.
|
Assessment: Approve I reviewed head Assumptions and rules checked (all held)
What I ran locally (x86_64 Linux)
Deriving the alias from the existing |
…commands # Conflicts: # docs/design/policy.md
|
Assessment: Approve (re-review at The new head merges Checked on the merged head (all held)
A note outside this PR's scope, not blocking: |
|
Assessment: Request Changes (re-review at The new head merges Checked on the merged head (held)
|
|
Assessment: Approve (re-review at The only change since Checked (held)
Nice fix: checking the order of the requests is better than updating only the count. |
…agent.ingress]] An agent that serves HTTP, such as a `BedrockAgentCoreApp` or a Strands agent behind a web server, cannot be reached in a box. The agent's sandbox allows only outbound connections, through the egress gateway, so nothing outside the sandbox can connect to the port the agent listens on. On Linux the Namespace backend refuses a listen port, and on macOS the Seatbelt profile refuses one. Box binds a listener in its trusted process and relays each caller to the agent's port. The agent's code does not change, and the agent gains no reach. - `box.toml`: `[[agent.ingress]]` is a list of up to five entries, so an agent that serves HTTP, MCP, and A2A on separate ports gets one listener for each. Each entry holds `listen`, an IP address and port that Box binds, and `workload_port`, the port the agent listens on in its sandbox. Both are required. Box binds every `listen` before the agent starts, so a port in use refuses the run. Each entry needs its own `listen` port and its own `workload_port`, and on macOS no `listen` port may equal any entry's `workload_port`. A `[[tool.<name>.ingress]]` is refused; a tool's ingress is not built yet. Ingress is experimental: `[[agent.ingress]]` loads only when `[experimental-features]` sets `ingress = true`, and is refused otherwise. - New crate `strands-box-ingress` (`ingress`): `Ingress`, `IngressConfig`, `Source`, `Workload`, and `IngressError`. `Ingress::start` accepts each caller, connects to the agent, and copies bytes both ways. - Linux: the agent's port exists only in its network namespace. The sandbox's PID 1 keeps the socket pair that egress already uses, marked close-on-exec so the agent never holds it. For each caller the relay asks PID 1 for a socket, and PID 1 creates an unconnected TCP socket in the namespace and sends it back. The relay connects it to `127.0.0.1:workload_port` itself, without blocking, with a timeout for each caller. Every listener's relay shares the one channel (`Workload::in_namespace_ports`). PID 1 sends one ready byte when its connector starts, and Box starts no accept loop until that byte arrives, at most 60 s. The listeners are bound meanwhile, so an early caller waits in the listen queue. Without this wait, a caller that arrived while the sandbox was still being set up timed out, and the timeout closed the channel for every listener. A socket keeps the namespace it was created in, so the connection reaches the agent. PID 1 never blocks, so a stuck agent cannot stall other callers. - macOS: Seatbelt renders `network-bind` and `network-inbound` on `(local tcp "localhost:<workload_port>")`, which allows that port on any address of the Mac, and the relay connects to `127.0.0.1:workload_port` (`Workload::loopback`). Before the agent starts, Box refuses to start when another process already listens on `workload_port`. A local process can also reach the agent's port directly; that is an accepted risk on macOS. A profile with no listen port is byte-identical. - Both platforms: the relay connects to `127.0.0.1` only, and PID 1 creates IPv4 sockets only. A relay that also tried `::1` would let another local user on macOS take callers while the agent is down, and on Linux the sandbox creates no IPv6 socket. When nothing accepts, the relay closes the caller and prints one line until a caller is served again. - Box raises its own soft open-file limit to the hard limit (`run::descriptor_limit::raise`), and the relay holds at most an eighth of that limit in callers at once, between 16 and 10,000 (`IngressConfig::connection_limit`), split evenly across the listeners. An eighth leaves room for the egress descriptors that each caller's request also opens. After an accept error, the relay waits one second. - Every child that Box starts gets the soft limit that Box started with (`run::descriptor_limit::restore_in_child`): each process that the trampoline starts (the agent, each tool, each contained MCP leaf) and each stdio MCP server. So only the box process holds the raised limit. - The record stores the agent's ingress in `[agent]` only. A record that holds one is version 29, so an earlier build refuses the box. Versions 24 to 28 came first on `main`; an ingress takes 29, the highest, even beside them. Every other record keeps its version and its bytes. - Docs: `docs/design/decisions.md` says `listen` now renders on both backends, `docs/user/config.md` gains `[[agent.ingress]]`, `crates/box/README.md` lists the field, and `docs/user/native-filesystem-policy.md` names version 29. This changes frozen surfaces and needs owner approval: `[agent]` gains a field, `[experimental-features]` gains `ingress`, `Record` gains version 29, `containment` lowers `Network::Localhost.listen` on both backends, and the new crate adds a public facade. No policy decision covers a caller; `listen` decides who can reach the agent. - `relay::tests::an_exhausted_descriptor_limit_does_not_spin`: a child process with a 64-descriptor limit and every descriptor taken, while the parent holds callers in the queue. The workload server runs in the parent, so the child's CPU time is the relay's alone. On Linux the relay without the backoff fails this test. macOS drops a connection when `accept` fails, so it cannot spin there. - `run::descriptor_limit::tests::a_child_starts_with_the_limit_the_box_had_before_it_raised_it`: the child starts at 256 after Box raises its own limit. Without the restore, the child starts at 10,240 and the test fails. - `supervise::tests::the_ingress_connection_limit_is_an_eighth_of_the_descriptor_limit`: 1,024 gives 128 callers, 10,240 gives 1,280, and the floor and the ceiling hold. - `inherited_handles_linux::the_workload_does_not_inherit_the_channel_to_pid_one`: the real trampoline with a listen port and the Unix socket channel attached; the workload holds no descriptor above stderr. With the `close_on_exec` call removed, the test fails and names the channel's descriptor. - `relay::tests::a_caller_beyond_the_limit_waits_until_one_closes`: the workload serves each connection on its own thread and counts them. With the limit replaced by 10,000, the test fails, because a second connection reaches the workload. - `netns::tests::a_connector_that_starts_late_serves_the_caller_that_arrived_first`: the real `serve_inbound` starts 6 s late, which is more than one answer may take, and a caller connects before it starts. That caller and the next one are served. - `workload::linux::tests::the_workloads_wait_until_pid_one_is_ready`, `a_channel_that_closes_before_ready_is_refused`, and `a_first_byte_that_is_not_ready_is_refused`. - `record::config::tests::an_agent_ingress_needs_the_ingress_switch` (omitted and `false` are refused, `true` loads) and `a_stored_ingress_needs_the_stored_switch`. - `workload::linux::tests::*` (fake PID 1): the relay connects the socket PID 1 sends; nothing listening is not ready and the channel stays open; an IPv6 socket, a datagram socket, an undefined answer, and a closed channel are refused. - `workload::macos::tests::a_listener_on_the_ipv6_loopback_alone_is_not_reached`. - `record::config::tests::an_ingress_is_declared_on_the_agent` (two entries, in order; the single-table `[agent.ingress]` spelling is refused) and `an_agent_ingress_stores_a_version_no_earlier_build_reads`. - `record::config::ingress::tests`: several entries on distinct ports are accepted; six entries, two entries on one `listen` port, and two entries on one `workload_port` are refused; on macOS, a `listen` port that is another entry's `workload_port` is refused, and on Linux each port mapped to itself is accepted. - `workload::linux::tests::workloads_on_one_channel_each_reach_their_own_port`. - `boundary::tests::the_ingress_reaches_the_agent_and_no_tool`: two entries give the agent's boundary both `workload_port`s, and a tool gets none. - `record::config::tests::an_agent_ingress_beside_a_shared_program_stores_the_ingress_version` and `an_agent_ingress_beside_an_absolute_mcp_command_stores_the_ingress_version`. - `profile_conformance::a_localhost_listen_port_renders_one_bind_and_one_inbound_rule`, `listen_ports_render_beside_the_composition_ports`, and `preflight_new_cells_macos::a_listen_port_is_the_only_port_the_workload_can_listen_on` (real kernel). - On `main` (`9c0bf1d`). macOS: `strands-box` 1302 passed, `strands-box-containment` 330 passed, `strands-box-ingress` 7 passed. Linux, in Docker (`rust:1-bookworm`, `/proc` covers unmounted, run as uid 1000 because `main` refuses a root launch that grants a directory write): `strands-box` 1324 passed, `strands-box-ingress` 16 passed. One macOS test, `tool_grammars::a_push_is_denied_until_a_test_exits_0_and_stays_allowed_after_a_restart`, fails the same way on `main` without this change. - Rebased on `main` (`ec5ef77`), after strands-agents#377 took record version 28 for an absolute MCP command, so ingress moved to 29. Before that, on `f4180a0`, which fixes the seccomp entry count: Linux `strands-box-containment` 693 passed and `strands-box-ingress` 16 passed, 0 failed in each, and the macOS `record::` and ingress tests pass. clippy shows no new warning in `box`, `containment`, or `ingress` on either platform, and fmt is clean. - Live, macOS: a `BedrockAgentCoreApp` answers through the relay, 20 parallel calls return 200, a held `workload_port` refuses the run, and a stopped agent serves again when resumed. Live, Linux: an agent's server answers through PID 1's socket, its port is unreachable from the container, 20 parallel calls return 200, and a stopped agent serves again when resumed. An agent that binds `::1` on Linux fails to start, because the sandbox creates no IPv6 socket. - Live, two listeners into one agent, on macOS and on Linux: each listener reaches its own server port, 20 parallel calls across both return 200, and on Linux neither agent port is reachable from the container. On macOS, crossed ports and six entries are refused at startup. On Linux, from this revision, the same box without `ingress = true` is refused with the experimental message. - AgentCore Runtime, from the revision before the readiness wait and the switch, with one `[[agent.ingress]]` entry: the probe, a Bedrock prompt, a WebSocket session, and 10 parallel calls return 200. The runtime's open-file limit is 1,024, and its log shows that the relay holds up to 128 callers. - AgentCore Runtime, from this revision, with `ingress = true` and two `[[agent.ingress]]` entries (`0.0.0.0:8080` to 8081, an HTTP app; `0.0.0.0:8000` to 8000, an MCP server in the same agent) and `allowedPorts` 8080 and 8000: `InvokeAgentRuntime` returns 200, and the session endpoint reaches both listeners. On port 8000, signed MCP `initialize`, `tools/list`, and `tools/call` succeed, the tools run in the agent's sandbox, 10 parallel calls return correct results, and a tool's fetch goes through the egress gateway, which permits example.com and refuses google.com. A Bedrock prompt and a WebSocket session on 8080 also pass. Not run: the GitHub MCP call through an AgentCore Gateway, because the egress `proxy` route is not on `main`.
The intro now names what Monty refuses and the host's Python runs: -m, -I, urllib.request and a project's own modules. It no longer offers python3 -m pytest or python3 -m venv .venv, which don't work on macOS with the example config. The macOS limits are now one list with their cause: a venv's packages aren't used, so a project's dependencies must be in the base Python, and venv with pip fails because shutil.copy2 calls chflags, which a box refuses in its write folders. The record-version list gains replaces at version 29, after #377 took 28.
The intro now names what Monty refuses and the host's Python runs: -m, -I, urllib.request and a project's own modules. It no longer offers python3 -m pytest or python3 -m venv .venv, which don't work on macOS with the example config. The macOS limits are now one list with their cause: a venv's packages aren't used, so a project's dependencies must be in the base Python, and venv with pip fails because shutil.copy2 calls chflags, which a box refuses in its write folders. The record-version list gains replaces at version 29, after #377 took 28.
The intro now names what Monty refuses and the host's Python runs: -m, -I, urllib.request and a project's own modules. It no longer offers python3 -m pytest or python3 -m venv .venv, which don't work on macOS with the example config. The macOS limits are now one list with their cause: a venv's packages aren't used, so a project's dependencies must be in the base Python, and venv with pip fails because shutil.copy2 calls chflags, which a box refuses in its write folders. The record-version list gains replaces at version 29, after #377 took 28.
Description
Core rejects an absolute stdio MCP executable because
command[0]also names the alias inbin/. This prevents selecting an installation outsidePATH, or a specific installation when another version comes first.Accept an absolute path in the existing
commandarray. Forcommand = ["/opt/tools/weather-mcp", "--stdio"], the harness callsweather-mcp --stdioand Core launches the configured file. Offline schema generation uses the same executable. A symbolic link keeps its invocation filename, while policy checks the resolved executable identity.Core already mediates stdio MCP through an executable alias in
<box_dir>/bin. The harness invokes that alias, either throughPATHor by its full alias path, and Core starts the declared server after authorization. Invoking the original host executable directly does not route through that broker. This launch model applies whether the alias name is derived or configured in a separate field.Why no new TOML field
command[0]already supplies the executable to launch. Its filename supplies the agent-facing alias, so path support does not require another operator choice. A separateexecutablefield would split the launch command across fields; analiasfield would add independent naming and validation rules. We chose the existing command array plus a derived filename for this feature.An explicit alias field would let the operator choose a name independently of the executable filename. We accept that naming limit for this feature; a differently named symlink can provide another invocation name when the program supports it. The decision is recorded at MCP executable filenames name their aliases.
Accepted limitations
/a/server --stdioand/b/server --stdioproduce the same harness invocation, so that duplicate is refused. Distinct arguments can distinguish servers; exact matches take priority and overlapping wildcard declarations are refused. Filenames retain the restricted character set and reserved names, includingpython3andsh.PATHor uses a literal absolute path. Its resolver has no base-directory rule for relative executable paths and does not expand~or${...}in the executable. Supporting those forms is separate from how the alias is named. A missing or invalid absolute target fails without falling back toPATH.Related Issues
None.
Type of Change
New feature
Testing
cargo test -p strands-box --locked --all-features: 1,339 passed, with five existing ignored tests. The non-UTF-8 pathname test reports its existing filesystem prerequisite skip on this Mac.mcp_schema_generation: 21 passed. The absolute-command test checksserver/discover,initialize,notifications/initialized, andtools/listin order, and retains the selected-tool and PATH-decoy assertions. The original merged-head assertion failed locally with four messages instead of three.runtime_mcp_start: 20 passed, including exact off-PATH selection, a PATH decoy, symlink invocation, no fallback, and canonical policy identity.The configuration regressions fail against the previous implementation.
Core and containment helpers build with
--locked --all-features. Formatting, Core clippy with the repository allowances, and the no-default-features build pass.The local deterministic suite is GREEN: 129 passed, 12 declared Linux-only cases skipped, full coverage, and no integrity problems.
The examples gate exits successfully and reports that no scripted examples remain. The live SDK tutorial was not run.
CI is rerunning for
247a396; its Linux and macOS workspace results are pending.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.