vim, full-screen CLI apps) behave correctly.
Sessions persist across WebSocket disconnections. If your connection drops, the process keeps running inside the capsule and you can reconnect using the session tag.
Endpoint
Upgrade: websocket headers.
Authentication
Your team’s API key.
Path parameters
The capsule ID.
WebSocket protocol
Client messages — starting a session
Send this as the first message to start a new PTY session:| Field | Type | Required | Default | Description |
|---|---|---|---|---|
type | string | Yes | — | Must be "start". |
cmd | string | No | "/bin/bash" | Command to run as the terminal process. |
args | string[] | No | [] | Arguments to pass to the command. |
cols | integer | No | 80 | Terminal width in columns. |
rows | integer | No | 24 | Terminal height in rows. |
envs | object | No | {} | Additional environment variables. |
cwd | string | No | — | Working directory for the process. |
user | string | No | — | User to run the process as. |
Client messages — reconnecting
To reconnect to an existing PTY session, send the tag you received in thestarted server message:
Client messages — during a session
Once the session is established (after receivingstarted from the server), you can send:
Input — keystrokes or pasted text, base64-encoded:
Server messages
type | Fields | When sent |
|---|---|---|
started | tag: string, pid: integer | Session started. Save tag to reconnect later. |
output | data: string | Terminal output, base64-encoded. Decode before rendering. |
exit | exit_code: integer | Terminal process exited. |
error | data: string, fatal: boolean | An error occurred. When fatal is true, the connection closes. |
ping | — | Keepalive from the server; no response required. |
All PTY data — both input you send and output you receive — is base64-encoded. Raw terminal bytes include ANSI escape sequences and control codes that are not valid UTF-8. Decode the
data field before passing it to your terminal renderer.PTY sessions survive WebSocket disconnections. The process keeps running in the capsule. Save the
tag from the started message and use {"type": "connect", "tag": "..."} to rejoin a session after a disconnect.Python SDK
The SDK wraps the WebSocket protocol and decodes base64 output automatically. Iterate over the session directly to receive events.Errors
| Status | Meaning |
|---|---|
404 | Capsule not found or does not belong to your team. |
409 | Capsule is not in the running state. Start or resume the capsule first. |