The PTY management endpoints live on the sandbox proxy host, not
https://api.tensorlake.ai:https://<sandbox-id-or-name>.sandbox.tensorlake.aiCreate, list, get, resize, and kill requests require Authorization: Bearer $TENSORLAKE_API_KEY. The WebSocket attach step also requires the per-session PTY token returned from session creation.Happy Path
- Call
createPty()orcreate_pty()on a connected sandbox client. - Tensorlake creates the PTY session, opens the WebSocket, and sends the initial
READYframe for you. - Use the returned handle to send input, resize the terminal, stream output, wait for exit, disconnect, reconnect, or kill the session.
- If you need to reattach later, call
connectPty()orconnect_pty()with the originalsessionIdandtoken.
High-Level SDK API
The connected sandbox client now exposes a high-level PTY handle instead of making you manage WebSocket framing yourself. The handle exposes:sendInput()/send_input()to write terminal inputresize()to change rows and columnswait()to block until the PTY exits and get the exit codedisconnect()to close the current WebSocket without killing the PTYconnect()to reattach the same handle laterkill()to terminate the PTY session over HTTPonData()/on_data()andonExit()/on_exit()to subscribe to output and exit events
- CLI
- Python
- TypeScript
Use
tl sbx ssh when you want an interactive terminal immediately and do not need to manage PTY sessions programmatically:tl sbx ssh uses the PTY API under the hood and requires an interactive terminal. For reconnectable sessions or application-managed PTY control, use the Python or TypeScript SDK.createPty() / create_pty() already open the WebSocket and send READY. Use connectPty() / connect_pty() only when you are reattaching to an existing session.Raw HTTP and WebSocket Flow
The raw protocol is small enough that you can drive it yourself from any HTTP client plus any WebSocket client. These calls assume you already have a running sandbox ID or sandbox name.1. Create the PTY session
2. Attach the WebSocket
Open this URL:?token=<pty-session-token> to the WebSocket URL instead.
3. Exchange PTY frames
| Direction | Bytes | Meaning |
|---|---|---|
| Client -> server | 02 | READY: flush any buffered output |
| Client -> server | 00 + UTF-8 bytes | Send terminal input |
| Client -> server | 01 + cols + rows | Resize terminal, with cols then rows as big-endian u16 |
| Server -> client | 00 + raw bytes | Terminal output |
| Server -> client | 03 + 4-byte big-endian signed int | Process exit code |
| Action | Bytes |
|---|---|
Send READY | 02 |
Run pwd\n | 00 70 77 64 0a |
Run exit\n | 00 65 78 69 74 0a |
Exit code 0 | 03 00 00 00 00 |
| Resize to 120x40 | 01 00 78 00 28 |
4. Close or abort
To close cleanly, writeexit\n to the shell and wait for the 0x03 exit frame followed by the normal WebSocket close.
To terminate the session immediately:
Notes
createPty()/create_pty()sendREADYfor you immediately after the socket opens.- Closing the WebSocket does not kill the PTY session. You can reconnect while the shell is still running.
- Persist the original PTY token if you plan to reconnect. Get PTY Session and List PTY Sessions do not return it again.
- PTY sessions with no connected clients are killed after 300 seconds of inactivity.
- You can resize either with the
0x01WebSocket frame or with Resize PTY Session. - For the endpoint-by-endpoint API reference, see PTY Sessions API.