Description
User Story
As a developer running coding agents in OpenShell sandboxes on a Bazel monorepo, I need in-sandbox loopback connections to work the same whether a client dials 127.0.0.1 or ::ffff:127.0.0.1, so dual-stack tools like Bazel can reach their own local servers.
Problem Statement
Inside a sandbox, a TCP connect to a loopback service succeeds when it's dialed as 127.0.0.1 (AF_INET) or ::1 (AF_INET6), but fails with EACCES when an AF_INET6 socket dials the same IPv4 listener as ::ffff:127.0.0.1. The supervisor logs this as a policy denial for 127.0.0.1:<port>, so the connection goes through policy evaluation even though its destination is loopback.
On #3735, a maintainer described the intended behaviour as: "The broker handles any loopback destination natively and only non-loopback TCP goes through the policy path." IPv4-mapped loopback doesn't follow that.
This isn't new in 0.1.8. On 0.1.7 the same connect was also denied, reported as ::ffff:127.0.0.1. Since #5101, the denial reports the normalized 127.0.0.1. #5101 covers [::ffff:127.0.0.1] for the Google metadata endpoint and the policy-local address, but not for other loopback ports.
Related but different:
- bug(network): transparent TCP opens to IPv4-mapped destinations are denied even when policy allows the IPv4 endpoint #5093 / fix(network): normalize IPv4-mapped transparent TCP destinations #5101: IPv4-mapped connects to non-loopback endpoints that policy allows (fixed in 0.1.8).
- bug(network): v4-mapped loopback flows (AF_INET connect to dual-stack listener) get no OCSF DENY event — silent RST or hold-then-timeout #3735: the reverse direction (
AF_INETclient to a dual-stack[::]listener).
Impact / Why This Matters
Dual-stack runtimes commonly dial IPv4 loopback addresses in mapped form, e.g. the Bazel client connecting to a server whose JVM runs with -Djava.net.preferIPv4Stack=true. In-sandbox services those clients depend on are unreachable, and the failure is reported as a policy denial. Adding policy rules doesn't help, because loopback isn't something a policy can allow.
On 0.1.8, the workaround is to drop preferIPv4Stack so the server listens on [::1], but that only works where the runtime lets you choose.
Acceptance Criteria
- An
AF_INET6connect to::ffff:127.0.0.1:<port>reaches an IPv4 listener on127.0.0.1:<port>in the same sandbox, the same as a nativeAF_INETconnect to127.0.0.1:<port>. - Such a connect doesn't produce a policy denial or require a policy entry.
- The loopback address matrix from bug(network): v4-mapped loopback flows (AF_INET connect to dual-stack listener) get no OCSF DENY event — silent RST or hold-then-timeout #3735 (
127.0.0.1,::1,::ffff:127.0.0.1, IPv4 vs. dual-stack listener) gives the same result for semantically equivalent flows.
Reproduction Steps
- Create a sandbox from an image with busybox
nc(no policy changes needed):openshell sandbox create --name v4m --from python:3.13-alpine - Start an IPv4-only listener on
127.0.0.1and connect to it as127.0.0.1, then again as::ffff:127.0.0.1(busyboxnc -lexits after one connection, so each connect gets a fresh listener):openshell sandbox exec -n v4m -- sh -c ' nc -l -s 127.0.0.1 -p 9000 >/dev/null & sleep 1 nc -vz -w 3 127.0.0.1 9000 nc -l -s 127.0.0.1 -p 9000 >/dev/null & sleep 1 nc -vz -w 3 ::ffff:127.0.0.1 9000'
Output:
127.0.0.1 (127.0.0.1:9000) open
nc: ::ffff:127.0.0.1 ([::ffff:127.0.0.1]:9000): Permission denied
The listener is IPv4-only (it's in /proc/net/tcp, not /proc/net/tcp6). A ::1 listener and a ::1 client connect fine.
Outside OpenShell, the same commands in a plain python:3.13-alpine container (podman run --rm python:3.13-alpine sh -c '…') connect both times:
127.0.0.1 (127.0.0.1:9000) open
::ffff:127.0.0.1 ([::ffff:127.0.0.1]:9000) open
Environment
- OpenShell: 0.1.8 (CLI and gateway)
- macOS (Apple Silicon), VM compute driver, gateway via Homebrew: reproduced with the steps above.
- Ubuntu 24.04 (kernel 6.8, Docker 29.1.3), Docker compute driver: same Bazel failure (client can't connect to its IPv4 loopback server). The reproduction steps above weren't run there.
- Also failed on 0.1.7 (VM driver).
Logs
[sandbox] [OCSF ] [ocsf] NET:OPEN [MED] DENIED /bin/busybox(0) -> 127.0.0.1:9000 [reason:transparent_tcp_policy_denied]
# Same failure from the Bazel client, in a sandbox that has network policies:
[sandbox] [WARN ] [openshell_supervisor_network::proxy] Denied staged transparent connection destination=127.0.0.1:44281 reason=endpoint 127.0.0.1:44281 is not allowed by any policy
[sandbox] [OCSF ] [ocsf] NET:OPEN [MED] DENIED /sandbox/.cache/bazelisk/downloads/sha256/<digest>/bin/bazel(0) -> 127.0.0.1:44281 [reason:transparent_tcp_policy_denied]
Activity
jbadeau commentedon Dec 1, 2026
I hit the same thing on 0.1.10 with .NET:
dotnet teston VSTest starts a testhost that connects back tovstest.consolethrough a dual-stackTcpClient, i.e. to::ffff:127.0.0.1. Inside a sandbox with no network policy it getsEACCESimmediately, and every VSTest run aborts after 90 s.127.0.0.1and::1connect fine from the same sandbox.The cause looks like
crates/openshell-sandbox/src/network_broker.rs(main @ 5479604, line 1081): local TCP is chosen withdestination.ip().is_loopback(), andIpv6Addr::is_loopback()is only true for::1. Classifying bydestination.ip().to_canonical()(and checking the metadata reservation against the canonical address too), while still connecting to the destination as given, fixes it in my testing. The protected control port is unaffected, since it is matched by port. I have a change with a broker test (AF_INET6connect to[::ffff:127.0.0.1]:<port>reaches a127.0.0.1listener; it times out without the change) and can open a PR if this is accepted.