Skip to main content
The PTY endpoint gives you a full interactive terminal inside a capsule. Unlike the exec and stream endpoints, PTY sessions allocate a pseudo-terminal device — the same infrastructure that powers SSH and terminal emulators. This means programs that rely on a TTY (interactive shells, editors like 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 this request to a WebSocket by including the standard Upgrade: websocket headers.

Authentication

string
required
Your team’s API key.

Path parameters

string
required
The capsule ID.

WebSocket protocol

Client messages — starting a session

Send this as the first message to start a new PTY session:

Client messages — reconnecting

To reconnect to an existing PTY session, send the tag you received in the started server message:

Client messages — during a session

Once the session is established (after receiving started from the server), you can send: Input — keystrokes or pasted text, base64-encoded:
Resize — when the terminal window changes size:
Kill — terminate the terminal process:

Server messages

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