Attach to a command's output and input

A WebSocket upgrade (RFC 6455).

GET/v1/sandboxes/{sandbox_id}/exec/{operation_id}/stream

A WebSocket upgrade (RFC 6455). Every frame is a text frame holding one JSON message. The server sends ExecStreamServerMessage: stdout and stderr chunks (base64), then one exit, then closes with code 1000. On failure it sends one error with an error body and closes with 1011. The client sends ExecStreamClientMessage: stdin chunks (base64) when the command was started with stdin: true, stdin_close, resize for a terminal, and signal. Reconnecting replays the kept tail of a detached process, then follows it live. Two ways in. A client that can send headers sends its key or token in Authorization, as on every call. A browser cannot, so it opens the stream with a ticket from createExecStreamTicket: new WebSocket(stream_url, ["pod.stream.v1", ticket]). The ticket travels in Sec-WebSocket-Protocol, never in the address, because addresses reach access logs (the edge network's in front of the gateway, and the gateway's own) and headers there are not logged. The server selects pod.stream.v1, never the ticket, so the answer does not repeat it. Every well-formed ticket an upgrade offers is spent before anything else is checked, whatever the outcome: an upgrade refused as unauthorized or invalid, or one that offers two tickets, leaves none of them usable. The upgrade is refused with unauthorized, one message for every cause, when the ticket is unknown, spent or expired; names another stream; arrives without an Origin header or from an origin other than the one it was made for; when the key or person that made it can no longer open this stream; or when the header offers a malformed ticket, two tickets, or a ticket without pod.stream.v1. An upgrade that carries both Authorization and a ticket is invalid. Tickets are never logged.

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
operation_idpathstringYes
Sec-WebSocket-ProtocolheaderstringNoWith a stream ticket: pod.stream.v1, pod_ticket_…. Without one, pod.stream.v1 may be offered and is then selected.

Errors

The refusals this call is known for: invalid, 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
TypeScriptproc.stdout, proc.stderr
Pythonproc.stdout, proc.stderr
mpodmpod sandboxes commands attach