Skip to content

feat(ingress): ingress relay for agent tcp communication - #272

Merged
rvkandury merged 1 commit into
strands-agents:mainfrom
rvkandury:feature/agent-ingress
Nov 10, 2026
Merged

rvkandury merged 1 commit into
strands-agents:mainfrom
rvkandury:feature/agent-ingress

Conversation

@rvkandury

@rvkandury rvkandury commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

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.

Solution

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.

Files

Change What it does Files
Configuration and record [agent] gains [[agent.ingress]], up to five entries of listen and workload_port. Ingress is experimental: it loads only with ingress = true in [experimental-features]. Box checks the count, unique ports, and on macOS that no listen port equals a workload_port. A tool's ingress is refused. A record with an ingress is version 29. record/config/ingress.rs (new), record/config/process.rs, record/config/mod.rs, ProcessSpec literals; docs/user/config.md, crates/box/README.md, docs/user/native-filesystem-policy.md, docs/design/decisions.md
The relay (new crate strands-box-ingress) Ingress::start accepts each caller up to a limit, connects to the agent's port, and copies bytes both ways. On Linux it waits until the sandbox's PID 1 reports ready, then asks PID 1 for a socket for each caller and connects it with a timeout; on macOS it connects over loopback. crates/ingress/**, Cargo.toml, Cargo.lock
The sandbox lets the agent listen Linux: PID 1 keeps the egress channel (close-on-exec, so the agent never holds it), sends one ready byte when its connector starts, and creates an IPv4 socket in the namespace for each caller. macOS: Seatbelt allows bind and inbound on each workload_port only. containment/.../namespace/{mod,netns,reaper}.rs, backend/macos/seatbelt.rs, model.rs, containment/Cargo.toml (test-only dependencies); tests inherited_handles_linux.rs, profile_conformance.rs, preflight_new_cells_macos.rs
run starts the relays Box binds every listener before the agent starts, gives only the agent's boundary the listen ports, and starts one relay per listener. On Linux all relays share one channel to PID 1. The caller limit is split across listeners. run/contain/supervise.rs, run/contain/boundary.rs, run/netns_relay.rs, error.rs
Open-file limit Box raises its own soft limit to the hard limit, so the relay can hold more callers, and gives every child it starts the original limit back. run/descriptor_limit.rs (new), run/contain/trampoline.rs, run/broker/mcp/server.rs

Paths under crates/box/src/ are shortened to run/… and record/….

Tests

  • 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_ports, 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 feat(mcp): support absolute executable commands #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.

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.

  • 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.

Comment thread crates/ingress/src/relay.rs Resolved
Comment thread crates/box/src/record/config/mod.rs Resolved
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Request Changes

The design is sound: the TCB binds the listener, PID 1 opens the connection inside the netns on request, and the relay checks the peer. Two problems block the merge. Callers that are not trusted can exhaust the trusted process's descriptors and keep it spinning (shown with a reproduction). And the new interface has no reference page. A ::1-only agent server is also unreachable and gives no error.

Review notes
  • Scope/process: about 1,330 changed lines across three crates, and it changes frozen surfaces ([agent] field, Record v24, Network::Localhost.listen lowering, new pub use set). It needs the owner approval that the description asks for, and the api/needs-review label. If you split the containment lowering from the box wiring, each part is easier to review.
  • Robustness of the TCB listener: the open caller-facing socket in the trusted process needs a backoff on accept errors and a bound on concurrent connections. The PID 1 timeout and the missing log are already listed as not done.
  • Tests: the relay tests cover the happy path and refusal. No test covers accept-error or descriptor pressure, and no test covers an IPv6-only workload.

Checked and held:

  • An ingress on [tool.<name>] is refused, and [mcp.<name>.ingress] is refused as an unknown field.
  • Only the agent boundary (RuntimeReach::Agent) gets listen. A leaf listens on nothing.
  • INGRESS_RECORD_VERSION takes precedence over 22/23, and no code reads version == 22/23 to choose behaviour.
  • A record without ingress keeps its version and bytes.
  • On Linux, listen ∩ connect is refused, and PID 1 serves only ports in listen.
  • The handoff is close-on-exec, so the agent does not hold it after exec.
  • The box binds listen before the spawn, so a port that is in use refuses the run before the agent starts.
  • On macOS, listen and workload_port on the same port is refused.

The PID 1 connector protocol is small, and the peer check makes it easy to audit.

Comment thread crates/box/src/run/contain/supervise.rs Resolved
Comment thread crates/ingress/src/relay.rs Resolved
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Assessment: Request Changes (re-review at 4123eaa)

All four earlier findings are fixed: the accept backoff and connection bound, the ::1 fallback, the reference docs, and the single owner for the record. The rework also removes the PID 1 connect stall. PID 1 now only creates sockets, and the box connects them without blocking. One item still blocks the merge: the new descriptor-exhaustion test is flaky because its own helper server spins. The other new comment is a suggestion about the raised file limit reaching child processes.

Checked at this commit and held
  • PID 1's serve_inbound does not block. A full backlog or a silent agent can no longer stall the channel or make it permanently Fatal.
  • connect_loopback covers servers bound to 0.0.0.0, 127.0.0.1, and on macOS ::1. On Linux, seccomp refuses AF_INET6 in the workload, so a ::1 bind fails when the agent starts, as config.md says.
  • The handed-back socket is checked for SOCK_STREAM and the requested domain.
  • The backoff holds when descriptors run out: the Tokio workers used 0 ticks during the flaky failure.
  • The macOS probe for a port already in use covers both loopback families.
  • The record has one owner for the ingress (agent.ingress), and version 24 is set from it.
  • The docs cover the table, the refusals, the disclosure line, and record version 24.

The new socket-handoff protocol is simpler than the connect-in-PID-1 design and harder to stall.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Assessment: Approve (re-review at e0faba0)

Both items from the last round are fixed, and I found nothing new that blocks the merge. The frozen-surface changes ([agent] field, Record v24, the listen lowering, the new crate's public facade) still need owner approval and the api/needs-review label, as the description says.

Checked at this commit and held
  • The descriptor-exhaustion test runs its workload server in the parent. The full ingress test binary passed 15 of 15 runs on Linux.
  • The raised open-file limit stays in the box. The trampoline and stdio MCP spawns restore it, and those are the only runtime spawns in crates/box/src. The limit is raised before the trampoline command is built. raised_limit_child really raises the limit on this host.
  • The relay, the macOS preflight, and PID 1 use IPv4 loopback only. config.md gives the listen requirement and what happens to a ::1-only agent on each platform.
  • The handed-back socket is checked as AF_INET/SOCK_STREAM. A wrong type is refused without dropping the channel.
  • PID 1's connector thread starts after the workload is forked, and it blocks every signal so the reaping loop still receives them.
  • PID 1 only calls socket(), which does not block, so an agent that accepts nothing cannot stall it.
  • The connection limit is an eighth of the limit, between 16 and 10,000, and the unit test covers each bound. The descriptor_limit and ingress tests in strands-box pass.

The handoff protocol and the child-limit restore are both small, and both are pinned by tests that fail without the fix.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Assessment: Approve (re-review at 6689b59)

The only change since e0faba0 is the rebase onto main. Every per-file diff is the same except the record-version bump, which main forced by taking v24 for shared-program MCP. The new code handles that bump correctly.

One thing to fix before owner sign-off: the PR description is out of date in three places, including the frozen surface owners are asked to approve.

  • It says "Record gains version 24", but ingress is now v25.
  • It says "PID 1 connects to 127.0.0.1:workload_port … and sends the socket back". PID 1 now only creates an unconnected socket, and the relay connects it.
  • The "Not done" note says the connect has no timeout and failures are not logged. Neither is true now: CONNECT_TIMEOUT is 5 s and the relay logs the refusal line. The description also leaves out the connection limit and the open-file limit changes.
Checked at this commit and held
  • record_version order: ingress (25) wins over shared program (24), process policy (23) and experimental (22). Later builds read every earlier format, so taking the highest applicable version is correct. an_agent_ingress_beside_a_shared_program_stores_the_ingress_version pins the combined case. a_record_from_another_format_is_refused now probes INGRESS_RECORD_VERSION + 1.
  • v25 is refused by a v24 build: the parse allow-list and the expected-version check both include v25, so a v24 build of main refuses an ingress box.
  • Every child gets the original file limit: after the rebase, runtime spawns in crates/box/src are still only the trampoline and the stdio MCP server, and both call restore_in_child.
  • The failure_tests.rs change is mechanical: the extra line is one more establish_pid_namespace_and_reaper(.., None, None) call site from main.
  • Tests on this Linux host: strands-box-ingress 12/12 pass. strands-box --lib ingress, descriptor_limit, boundary and record-version tests pass, 74/74, once the workspace bins are built. The containment netns and reaper tests fail here because this runner forbids user namespaces (unshare -Ur gets EPERM), which matches the PR's note about main.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Assessment: Approve (re-review at 595b0ed)

This is another rebase onto main. main now uses record versions 25 (file attributes), 26 (MCP argument wildcards) and 27 (shell limits), so ingress moved to v28. The ingress crate and descriptor_limit.rs are byte-identical to 6689b59, and the other changes are the version bump plus mechanical ingress: None and false arguments in main's new tests.

The PR description is still out of date, and it now asks owners to approve the wrong version: it says "Record gains version 24", but the code writes 28. The PID 1 connect and "Not done" notes from my last summary are also unchanged.

Checked at this commit and held
  • record_version order: ingress (28) is checked before limits (27), wildcards (26), file attributes (25), shared program (24) and process policy (23). Later builds read every earlier format, so the highest version wins. The parse allow-list includes 28, and a_record_from_another_format_is_refused probes INGRESS_RECORD_VERSION + 1.
  • Tool grammars: [tool.<label>] can now hold grammar, and an ingress on a tool is still refused before any other check.
  • Every child gets the original file limit: the trampoline and the stdio MCP server are still the only runtime processes that exec, and both restore the limit. The new fork in linux_enforcement/probe.rs runs only syscalls and never execs.
  • Tests on this Linux host: strands-box-ingress 12/12. strands-box --lib record:: 260/260. The ingress, descriptor_limit, boundary and version tests 78/78.

@ferdingler ferdingler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two findings to address: connector readiness during Linux startup, and the caller-limit regression test.

Comment thread crates/box/src/run/contain/supervise.rs Resolved
Comment thread crates/ingress/src/relay.rs Resolved
Comment thread crates/box/src/record/config/process.rs Resolved
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Assessment: Approve (re-review at 006ec00)

This push addresses all three of @ferdingler's findings, and I found no new defect. The PR description now matches the code: [[agent.ingress]], v28, and the relay connects.

The review findings, checked at this commit
  • Connector readiness: PID 1 now sends R before it answers any request. Workload::in_namespace_ports waits up to 60 s for it and only then switches to the 5 s per-answer timeout, so a slow namespace setup no longer clears the shared channel. Every way that wait can end is handled:
    • If the connector thread fails to spawn, or PID 1 dies, the box sees EOF. It returns NotReady, stops the process group, and refuses the run.
    • A box with no ingress never creates the connector, so nothing writes to the dropped box side.
    • If the first byte is not R, the run is refused.
    • When I removed the wait locally, four ingress tests failed. The new containment test drives the production serve_inbound with a 6 s delay, as requested.
  • Caller-limit test: counting_server now serves each connection on its own thread. With Semaphore::new(10_000) swapped in, a_caller_beyond_the_limit_waits_until_one_closes now fails, so the test catches a broken cap.
  • Experimental flag: without ingress = true, [[agent.ingress]] is refused both when box.toml loads and when a stored record loads. Tests cover the flag omitted, the flag false, and the enabled path, and the docs show the opt-in.
    • A flag set with no entries keeps v21. It writes ingress = true under [experimental-features], which an older build refuses with a parse error. tool-grammars already behaves this way.

Tests on this Linux host: strands-box-ingress 16/16. strands-box --lib record::, descriptor_limit, ingress and run::contain 402/402. In containment, the real-connector readiness test passes. The other namespace test there can't run on this host because it allows no user namespaces.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Assessment: Approve (re-review at 4ffb4a2)

I compared this push with 006ec00, the commit I last reviewed. git range-diff shows the same patch, rebased onto three new main commits (#271, #348, #381). Only the commit message changed. The rebased tree builds, and the PR's tests pass on this Linux host:

  • strands-box-ingress: 16/16.
  • strands-box --lib (record::, descriptor_limit, ingress, run::contain): 402/402.
  • Containment, including a_connector_that_starts_late_serves_the_caller_that_arrived_first: 474 passed. The 12 failures are namespace tests, and this host has no user namespaces.

Suggestion (non-blocking): docs/design/decisions.md still says listen is refused, and this PR makes that untrue.
Example: The entry #localhost-names-the-ports-the-workload-reaches says "Only connect renders. Both backends refuse a non-empty listen, so the field does not yet support inbound binds." With this PR, both backends lower listen: Seatbelt renders network-bind/network-inbound, and on Linux PID 1 creates the sockets. The approved design that #271 just merged (team/designs/0003-ingress-relay.md, "Decisions" section) says ingress "replaces the recorded decision that Network::Localhost.listen is an unimplemented field." This is the decision that root AGENTS.md ("Record an entry in docs/design/decisions.md only after the user decides it") requires before the entry changes. After merge, crates/containment/AGENTS.md sends readers to that file for the "why", and they would find the opposite of what the code does.
Suggestion: Rewrite that entry, using the kd skill, to say that listen renders on both backends: the Seatbelt port rule on macOS, and PID 1's sockets on Linux. Link it to the 0003 design.

Checked and held
  • Readiness, the caller-limit test, and the experimental switch are unchanged since the previous review, and the tests that cover them pass after the rebase.
  • The rules in the newly merged design doc that I checked match the code: up to five entries, unique listen ports, port 0 refused, the macOS cross-port refusal, PID 1 keeping the channel close-on-exec, and the descriptor backoff.
  • On stop, group.stop() sends SIGTERM, waits STOP_GRACE, then sends SIGKILL. An agent that drains on SIGTERM therefore lets in-flight relayed callers finish. That matches the design's bounded drain.
  • fix(linux): allow root directory write grants #348 and fix(box): skip hard-link scans when Linux mount and filename checks pass #381 touch namespace/mod.rs and the mount and hard-link code next to this PR's keep-list change. The patch is unchanged, it compiles, and the namespace tests that can run here pass.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Assessment: Approve (re-review at 806e171)

I compared this push with 4ffb4a2, the commit I last reviewed. git range-diff shows the same base (f4180a0) and the same code. The one change is the rewrite of the decisions.md entry I suggested. I have no new findings.

Checked and held
  • The rewritten #localhost-names-the-ports-the-workload-reaches now matches the code: listen renders as the Seatbelt port rule on macOS and as sockets from PID 1 on Linux.
  • The relative link ../../team/designs/0003-ingress-relay.md resolves. docs/site-manifest.json does not publish docs/design/, so a link outside docs/ does not break the site.
  • The anchor did not change, so the existing links to this entry still work.
  • The commit message now names the doc change in its Docs line.

@rvkandury

Copy link
Copy Markdown
Contributor Author

Addressed all comments. @ferdingler . Ready for another review.

…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`.
@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review at 5e687cf)

I compared this push with 806e171, the commit I last reviewed. The push rebases onto ec5ef77. #377 took record version 28 for an absolute MCP command, so ingress moves to 29. The range-diff touches only record/config/mod.rs, native-filesystem-policy.md, and the commit message. I have no new findings.

Checked and held
  • Version cases: I traced each case through record_version and Record::parse, which requires the exact version.
    • Ingress alone stores 29.
    • Ingress beside an absolute MCP command stores 29, because the ingress check comes first. The new test covers this case.
    • An absolute command alone still stores 28.
    • A v28 record from main still parses, because 28 stays in the accepted list.
    • A v29 record is refused by ec5ef77.
  • Docs: native-filesystem-policy.md lists 28 for an absolute command and 29 for ingress, and the "retain version 21/22" sentence names both conditions. mcp.md's "28 or newer" is still correct.
  • Local runs: strands-box record:: 276 passed, and strands-box-ingress 16 passed. Clippy finds no warning in a file this PR touches; the 6 existing warnings are all in crates/shell.

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.

2 participants