There are two ways to drive an interactive shell inside a sandbox:Documentation Index
Fetch the complete documentation index at: https://docs.tensorlake.ai/llms.txt
Use this file to discover all available pages before exploring further.
- SSH — connect with
ssh,scp,sftp,rsync, VS Code Remote-SSH, JetBrains Gateway, and any other tool that speaks SSH. Use this when you want a normal terminal, file transfer, or port forwarding. - PTY sessions — create a PTY over HTTPS, attach to it over a WebSocket, and drive terminal I/O programmatically. Use this when you’re building a UI or browser app that needs a shell, when you need WebSocket-only access, or when you want a session you can disconnect and reattach by token.
SSH
The Tensorlake sandbox proxy exposes a standard SSH endpoint atsandbox.tensorlake.ai. The username is the sandbox id (or name); your laptop’s SSH key, registered once with your Tensorlake account, authenticates the connection.
One-time setup
Connect
/home/tl-user as the tl-user POSIX account, which is in the sudo group. The sandbox’s hostname inside the session is tl-sbx.
To target a specific port (default is the SSH server on 22), prefix the username with the port:
File transfer
scp, sftp, and rsync ride the same connection:
Port forwarding
All four standard forwarding modes are supported — TCP and UNIX-socket, each direction. Local forward (-L) — reach a service running inside the sandbox from your laptop:
-D) — route arbitrary traffic through the sandbox’s network namespace:
-R) — let processes inside the sandbox reach a service running on your laptop:
VS Code Remote-SSH
Add an entry to~/.ssh/config:
my-sandbox. VS Code installs its server inside the sandbox automatically. JetBrains Gateway, Cursor, and any other Remote-SSH client work the same way.
Persistent shells
tmux and screen work normally inside the sandbox — useful if you want a session that survives an ssh disconnect:
Troubleshooting
When auth fails, the proxy disconnects with one of three specific messages. Key not registered.tl ssh-keys add ~/.ssh/id_ed25519.pub.
Sandbox not in any of your projects.
tl sbx ls -r to see running sandboxes in your active project.
Sandbox is not running.
running. For named sandboxes, tl sbx resume <id>; otherwise create a fresh one.
If your client offers multiple keys and one is unregistered, you’ll see the static banner followed by Permission denied (publickey). because OpenSSH iterates through them. Constrain it to the registered key:
CLI shortcut
If you don’t need standardssh semantics — e.g. you just want a quick shell without setting up keys — tl sbx ssh opens an interactive PTY using the WebSocket flow described below:
tl sbx ssh requires an interactive terminal and doesn’t support port forwarding or file transfer — use ssh, scp, etc. for that.
PTY sessions
Use PTY sessions when you need to drive an interactive shell programmatically — for example a browser-based terminal UI, a recorder, or a remote-control tool — without a real SSH client. The session is created over HTTPS and terminal I/O moves over a WebSocket.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.Disconnect or kill
disconnect() closes the WebSocket but leaves the PTY running, so you can reattach later with connectPty() / connect_pty(). kill() terminates the session over HTTP.
- Python
- TypeScript
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.
Related Guides
Commands
Run one-shot commands without an interactive shell.
Processes
Long-running background processes managed by the sandbox daemon.
Local Tunnels
Forward arbitrary TCP ports (Postgres, VNC, custom binary protocols) over an authenticated WebSocket.
Lifecycle
How long a sandbox lives, and what happens on suspend, resume, and terminate.