The port that answers on one loopback and refuses the other

L2WorkingDebug6 minDebuggingCoding

RolesAgent Systems EngineeringLLM Product Engineering

The question

You publish 18081:8080 with sbx ports. A client on the host that connects to [::1]:18081 gets a refused connection, while 127.0.0.1:18081 answers 200. Explain the default, write the spec that fixes it, and name the two other sbx verbs whose rules differ from their docker counterparts.

Answer it first, aloud or on paper. Then open the answer.

The answer

Show short answer

Without a protocol in the spec, the publish command uses tcp4, so the host binding is 127.0.0.1 alone; that changed in v0.42.0, and the recorded curl to ::1 failed with exit 7. Publish 8080/tcp to bind both loopbacks, each on an ephemeral host port, and unpublish without a protocol removes either form. The other two verbs are sbx exec, which runs as the agent user, starts a stopped sandbox and has no detached mode, and sbx cp, which needs one side written as SANDBOX:PATH and refuses a copy between two sandboxes.

Show full answer

The address family table

PROTOCOLHost binding when HOST_IP is omitted
none127.0.0.1 as tcp4, or tcp6 on ::1 when HOST_IP is an IPv6 address
tcp, udp127.0.0.1 and ::1, or 127.0.0.1 alone when the sandbox is IPv4-only
tcp4, udp4127.0.0.1
tcp6, udp6::1

sbx ports SANDBOX --json lists every binding as host_ip, host_port, sandbox_port and protocol, and sbx ls prints them in its PORTS column. -p on sbx run applies at creation only and is ignored on re-attach, so later changes go through sbx ports. Publishing starts a stopped sandbox first. In the cloud a published port gets a public URL and UDP is refused.

exec and cp

sbx exec runs the command as uid 1000 in the sudo and docker groups, in the workspace directory, and -u root is how the help installs packages. -d appears in the help only to say that detached exec is not supported, and with --cloud the flags -d, --user and --privileged are rejected rather than ignored. Inside, SANDBOX_NAME and SANDBOX_ID name the sandbox and WORKSPACE_DIR names the mount.

sbx cp SRC DST takes one sandbox side as SANDBOX:PATH and one host side. The recorded copy from one sandbox to another exited 1 with copying between sandboxes is not supported, so such a copy goes through the host in two steps. A sandbox path is a container path, so a file under /tmp sits outside the workspace mount and disappears with the sandbox. Copy-out had a security history: release v0.38.0 fixed CVE-2026-17106, a flaw that let a copy-out escape its destination.

Follow-ups

  1. L2WorkingYou re-attach with -p 18081:8080 on a sandbox created without it, and nothing is published. Why?

    Show expected answer

    -p applies at creation only; use sbx ports --publish on the existing sandbox.

  2. L3Seniorsbx cp a:/tmp/x b:/tmp/x fails. How do you move the file?

    Show expected answer

    two copies through a host path, because sandbox-to-sandbox copy is not supported.

  3. L3SeniorWhy does --cloud reject --privileged rather than ignore it?

    Show expected answer

    a silently ignored flag would let a script believe it ran privileged; refusal keeps the local and cloud behavior honest.

  4. L4StaffYou bound 8080/tcp and later unpublish 8080 with no protocol. What remains?

    Show expected answer

    nothing; unpublish without a protocol removes the default form and the dual-stack form alike.

Wrong answers

Show the wrong answers that interviewers hear
  • “IPv6 is turned off inside the VM.”

    The binding family is a host-side choice made by the protocol in the spec.

  • “Unpublish must repeat the protocol you published with.”

    It removes the mapping in both cases without one.

  • “sbx exec -d runs the command in the background.”

    Detached exec is not supported; the flag exists in the help to say so.

Taught in

The exec, cp and ports section records the tcp4 binding, the two curl results and the refused copy.