Pty module provides interactive pseudo-terminal (PTY) sessions over WebSocket. Access it via sandbox.pty.
Creating a PTY Session
await sandbox.pty.create(**kwargs)
Opens a new interactive terminal session.
Terminal width in columns.
Terminal height in rows.
Callback invoked when the terminal produces output.
PtySession
PtySession
PtySession is a dataclass with the following interface:
| Property / Method | Type | Description |
|---|---|---|
session_id | str | Unique session identifier |
sandbox_id | str | ID of the parent sandbox |
send(data) | async (str | bytes) -> None | Send input to the terminal |
recv() | async () -> bytes | Receive output from the terminal |
close() | async () -> None | Close the PTY session |
Examples
Run an Interactive Command
Manual Receive Loop
PTY sessions use WebSocket connections under the hood. Each session maintains a persistent connection to the sandbox worker.