Skip to content

Sandbox supervisor keeps listening on loopback ports after the application closes them #5300

Open

Description

@Nikzz3

Problem

Inside a sandbox, once a process binds a loopback port and then closes it, the port keeps accepting connections. The supervisor (PID 1, openshell-sandbox) appears to keep a listener on the port after the original process has released it, so a later connect() to 127.0.0.1:<port> succeeds even though no application is listening.

This breaks any tool that probes for a free port by binding, closing, then checking that nothing answers. Each probe makes the port it tested look busy for good. Examples:

  • T3 Code's remote SSH launcher scans 3773–3972 this way and fails on every port with "Failed to find an available port on the remote host".
  • Dev servers that probe for a free port (bind → close → connect check) drift upward or give up.
  • A server restarted on the port it used before cannot be told apart from a live one by a connect probe.

Steps to reproduce

Observed on OpenShell 0.1.3 (macOS host, linux/arm64 sandbox) through T3 Code's port picker. Minimal repro of the same pattern:

# inside a sandbox
python3 - <<'PY'
import socket
s = socket.socket(); s.bind(("127.0.0.1", 45123)); s.listen(); s.close()
c = socket.socket(); c.settimeout(2)
print("connect after close:", c.connect_ex(("127.0.0.1", 45123)))  # 0 = accepted
PY

Expected: connect_ex returns ECONNREFUSED (111) once the only listener has closed.
Actual: the connection is accepted, and the listener belongs to the supervisor (PID 1, openshell-sandbox), not to any application process.

Ports that no sandbox process has ever bound refuse connections as expected.

Expected behavior

The supervisor stops listening on a loopback port once the sandbox process that bound it has closed it, or the forwarding/ingress behavior that needs the listener is opt-in per port (for example only ports declared through openshell service expose or sandbox forward).

Context

Found while connecting the T3 Code desktop app to an OpenShell sandbox over SSH (downstream: Swisscom Saito). The workaround is to start the server ourselves on a port found with a connect-only probe, which never binds and so never poisons a port.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:triage-neededOpened without agent diagnostics and needs triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions