A PTY session is a full interactive terminal inside the sandbox — like SSH but over WebSocket. Supports colors, cursor movement, and full-screen applications (vim, htop).
import { Sandbox } from "@opencomputer/sdk";
const sandbox = await Sandbox.create();
const pty = await sandbox.pty.create({
onOutput: (data) => process.stdout.write(data),
});
pty.send("ls -la /app\n");
// ... wait for output ...
pty.close();
await sandbox.kill();
Creating a PTY
const pty = await sandbox.pty.create({
cols: 120,
rows: 40,
onOutput: (data) => process.stdout.write(data),
});
Parameters
| Parameter | Type | Default | Description |
|---|
cols | number | 80 | Terminal columns |
rows | number | 24 | Terminal rows |
onOutput | callback | — | Called with output data (TS: Uint8Array, Python: bytes) |
PtySession
| Member | TypeScript | Python | Description |
|---|
| Session ID | pty.sessionId | pty.session_id | Unique session ID |
| Send input | pty.send(data) | pty.send(data) | Send keystrokes or commands |
| Receive output | via onOutput callback | await pty.recv() | Get terminal output |
| Close | pty.close() | await pty.close() | Close the PTY session |
recv() is Python-only — a pull-based alternative to the on_output callback. Returns raw bytes.
Resize
PTY resize is available via the HTTP API only (POST /api/sandboxes/:id/pty/:sessionID/resize). The SDKs do not expose a resize method — the CLI handles resize automatically for interactive sessions.
CLI
The fastest way to get an interactive shell:
oc shell sb-abc123
oc shell sb-abc123 --shell /bin/zsh
Terminal size is auto-detected and resize events are forwarded. See oc shell for details.