Skip to main content

PTY (interactive terminals)

VoidRun exposes pseudo-terminal (PTY) access over WebSocket so you can run interactive shells, REPLs, and full-screen TUIs inside a sandbox. The canonical contract is in OpenAPI under the PTY tag (paths like /sandboxes/{id}/pty and /sandboxes/{id}/pty/sessions/{sessionId}).

When to use PTY vs exec

See Code execution for exec and streaming exec.

Ephemeral vs persistent

Persistent sessions also support REST helpers without a live socket: execute, buffer, resize, list, and delete. Several clients can attach to the same session; output is broadcast to all of them. On reconnect, the agent sends a ring buffer of recent output (up to about 64 KB, trimmed to the last ~32 KB when full), then live output.

Session cleanup (persistent)

Persistent PTY has no idle auto-close when the last client disconnects. The bash process keeps running. Unlike file watching, there is no grace timer after the last WebSocket client leaves.

Auto-sleep interaction

An open or background persistent PTY does not keep the sandbox awake by itself. Idle auto-sleep (default ~60 seconds) uses sandbox lastActivityAt, which is refreshed when API handlers run — for example PTY connect (WebSocket upgrade), create/list/delete session, execute, buffer, resize, exec, and filesystem calls. Ongoing WebSocket traffic (typing, shell output, keepalive pings) does not reset that timestamp. So after connect, if you only use the live terminal and make no further API calls, the sandbox can still auto-snapshot while the socket looks “active.” When that happens, the PTY session is lost with the VM. To keep a sandbox running through long interactive work:
  • Create with autoSleep: false, or
  • Periodically call an API that touches activity (for example a cheap exec), or
  • Rely on other REST traffic that already hits the sandbox
See Sandbox lifecycle for idle defaults and autoSleep.

HTTP and WebSocket flow (overview)

  1. Create or resume a sandbox.
  2. For a durable session, create a PTY session via the REST API (see API Reference → PTY).
  3. Open the WebSocket URL documented in OpenAPI for that session (or the ephemeral PTY endpoint, depending on your use case).
  4. Send/receive terminal data over the socket; resize and lifecycle operations follow the spec.
Exact query parameters, upgrade headers, and message framing are defined in docs/openapi/voidrun.yml (synced from voidrun/openapi.yml).

SDKs

Prefer the SDK when possible; it sets X-API-Key and the default hosted API base (same as OpenAPI servers) from VR_API_KEY alone. For self-hosted APIs, override with VR_API_URL or baseUrl / base_url: see Self-hosted deployments.

Next steps

Interactive PTY example

Ephemeral and persistent patterns in TypeScript and Python.

Sandbox lifecycle

Auto-sleep, activity tracking, and autoSleep.

API Reference

OpenAPI PTY operations and WebSocket URLs.

Code execution

Non-interactive exec and interpreter usage.