Skip to main content
A task’s machine exposes one realtime connection, its live socket: a multiplexed WebSocket that carries terminal I/O, file operations, live agent events, port changes, and git diffs over a single socket. The web app, the phone and the aether CLI all speak this same protocol.

Endpoint

{liveConnectionID} is the live connection POST /tasks/{taskID}/connect answered. Do not build this address yourself: dial the websocket_url that call answers. The ticket that call answers is the socket’s only credential. For a sandbox, the API checks it, dials the task’s sandbox and copies text frames both ways. Every other documented surface is REST.

Connecting

Name the task, not the workspace. Call POST /tasks/{taskID}/connect first. It answers a union on state. Opening a live connection never starts a sandbox unless you ask it to. start_sandbox is optional and false by default, so merely viewing a task can never bring its sandbox up. Starting is an explicit act: "start_sandbox": true.
1

Open a live connection

Call POST /tasks/{taskID}/connect with {"protocols": [1]}, the live protocol versions you speak.
2

Start a stopped sandbox, if the person chooses to

state: "stopped" means the sandbox is stopped. Offer to start it, then call again with "start_sandbox": true, once, on the call that expresses that intent, and with it false on every later call of that attempt.
3

Wait while it comes up

state: "starting" carries since, retry_after_ms and waiting (its code and a message to show). Call again after retry_after_ms, and give up by your own deadline, counted from since.
4

Open the socket

state: "ready" carries websocket_url, a ticket, ticket_expires_at, the protocol chosen, and preview_url_template. Dial websocket_url within 30 seconds, offering the ticket in the subprotocol header (see below). A ticket opens one socket once: every attempt to open a socket starts with a fresh call.

When it refuses

A refusal carries a code. The task’s can.connect_live shows the refusals that come from the task and its sandbox before you call: read it from GET /tasks/{taskID} to show the reason without trying. Only the call can answer live_protocol_unsupported, a full computer’s too_many_live_connections, and a start’s runtime admission (402), so handle those on the call itself. The ready response shape:
preview_url_template is the address of a port on the machine, with {port} to fill in. See preview URLs.

Authentication

The socket takes the ticket alone. Offer two WebSocket subprotocols, bearer and then the ticket; the server selects bearer. Never put the ticket in the address.
Your own session token or API key opens no socket, in a header or in the address: authenticate POST /tasks/{taskID}/connect with it, and dial with the ticket that call answers. A ticket that is malformed, expired, already used or for another connection is refused with 401 and no body before the upgrade.

Message Format

Every message is JSON with a channel field identifying the target subsystem and a type field identifying the message within that channel. Six channels are multiplexed over the connection: Client messages are validated against strict schemas — extra or misnamed fields are rejected. The canonical shapes live in packages/workspace-protocol/src/messages.ts.

The error Channel

The server pushes errors on a dedicated channel that you never send to. It is emitted after the socket opens when the VM fails to initialize or an inbound message fails to parse.
Every close carries a code and its name as the reason. When the API cannot reach the sandbox, the socket closes with 4410 machine_left; when access to the task was taken away, with 4403 access_ended. Either way, open a new live connection with a fresh call to POST /tasks/{taskID}/connect, which says what changed.

Connection Keepalive

The API sends WebSocket ping frames every 15 seconds. If no pong arrives within 120 seconds, it closes the connection.

Reconnection

On reconnect, what comes back depends on the channel:
  • Terminal sessions keep running on the VM while you’re disconnected; reattach by sending create with the same sessionId.
  • Ports sends a fresh snapshot of currently-open ports on connect.
  • Agent resumes only live task_event messages for tasks you re-subscribe to. Conversation history is not replayed over the socket — fetch turn summaries and per-turn activity over REST.
  • Files does not replay change events that occurred while disconnected; re-list or read to get current state.
Prompting an agent, responding to its questions, and stopping a task all happen over REST, not the WebSocket. See the agent channel.