Open a raw TCP or UDP connection to a port

A WebSocket upgrade (RFC 6455) whose binary frames are the bytes of one TCP connection to the port, each way.

GET/v1/sandboxes/{sandbox_id}/ports/{port}/connect

A WebSocket upgrade (RFC 6455) whose binary frames are the bytes of one TCP connection to the port, each way. With protocol=udp each binary frame is one datagram instead. mpod sandboxes ports forward and an SSH ProxyCommand are built on it. A text frame from the client ends the connection. The port is connected before the upgrade, so a port nothing listens on answers port_closed instead of a socket. A sleeping sandbox is woken first, waiting up to 30 seconds (not_ready after). An open connection is checked again every 30 seconds and closed once its key is revoked or loses sandboxes:exec. A key sends Authorization, as on every call; a browser has no use for raw bytes, so no stream ticket opens it.

A key with the sandboxes:exec scope.

Request

A WebSocket. Open the stream_url the command's answer gives, with your key in Authorization; a browser opens it with a stream ticket instead. The SDKs open it for you.

Parameters

NameInTypeRequiredWhat it is
sandbox_idpathstringYes
portpathintegerYesA TCP or UDP port number, 1 to 65535.
protocolquery"tcp" | "udp"No

Errors

The refusals this call is known for: invalid, port_closed, not_ready, not_found, in_other_cell. Any call can also answer unauthorized, rate_limited, unavailable or internal; the error list says what each means and when to send the call again.

In the SDKs

ClientCall
TypeScriptpod.ports.connect(sandboxId, port)
Pythonpod.ports.connect(sandbox_id, port)