Attach to a PTY session over WebSocket
PTY Sessions
Attach PTY WebSocket
Upgrade to a WebSocket connection for an interactive PTY session.
GET
Attach to a PTY session over WebSocket
Attach to a PTY session over WebSocket.
Use the WebSocket endpoint on the sandbox proxy host:
Query-string token:
Endpoint
Authentication
You must provide the PTY token returned from Create PTY Session. Tensorlake accepts the token in either place:- Preferred:
X-PTY-Token: <token> - Backward-compatible fallback:
?token=<token>
WebSocket Protocol
After connecting, send a binaryREADY frame immediately so Tensorlake can flush any buffered output.
For an end-to-end example that creates the session, sends READY, runs a command, reads output, and closes cleanly, see PTY Sessions.
Client-to-server opcodes
| Opcode | Meaning | Payload |
|---|---|---|
0x00 | Data | Raw terminal input bytes |
0x01 | Resize | cols as big-endian u16, then rows as big-endian u16 |
0x02 | Ready | No payload |
Server-to-client opcodes
| Opcode | Meaning | Payload |
|---|---|---|
0x00 | Data | Raw terminal output bytes |
0x03 | Exit | Exit code as big-endian i32 |
Example Connection
Header-based token:Connection Semantics
- If the token is invalid, Tensorlake returns
403 Forbiddenwith codeINVALID_TOKEN. - If the session does not exist, Tensorlake returns
404 Not Foundwith codeSESSION_NOT_FOUND. - When the process exits, Tensorlake sends the
0x03exit frame and then closes the WebSocket with reasonexit:<code>. - If the PTY session is terminated while the socket is open, Tensorlake closes the WebSocket with code
1001and reasonsession terminated. - If you do not send
READY, Tensorlake buffers output up to 1 MB before disconnecting the client.
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
Preferred PTY session token header for WebSocket authentication.
Path Parameters
The PTY session identifier.
Query Parameters
Optional PTY token. Prefer the X-PTY-Token header instead of the query string.
Response
WebSocket upgrade successful