Skip to main content
The TypeScript SDK exposes PTY support through sandbox.pty. The module has three callables you’ll use directly: pty.create() to start a new session, pty.connect() to reattach to an existing one, and the low-level pty.sendStdin / resize / kill trio when you already hold a pid. For conceptual background see the PTY feature overview.

sandbox.pty.create(opts?)Promise<PtyHandle>

Create a new PTY session. The sandbox spawns an interactive bash -l login shell with TERM=xterm-256color pre-set.

PtyCreateOpts

sandbox.pty.connect(pid, opts?)PtyHandle

Reattach to a PTY session that’s already running. Returns a fresh PtyHandle that streams live output from the moment it connects. Multiple clients can be attached to the same pid concurrently.

PtyConnectOpts

PtyHandle

Returned by both create() and connect().

Properties

  • handle.pid: number — remote process id.

Methods

handle.sendInput(data: Uint8Array | string, requestTimeout?: number): Promise<void>

Forward input to the shell. Strings are UTF-8 encoded.

handle.resize(size: PtySize, requestTimeout?: number): Promise<void>

Change the remote terminal dimensions. Fires SIGWINCH inside the sandbox so ncurses apps redraw.

handle.disconnect(): void

Stop consuming output without killing the remote process. A later sandbox.pty.connect(pid) reattaches cleanly.

handle.kill(requestTimeout?: number): Promise<boolean>

Terminate the remote shell. Returns true if the session existed at the time of the call.

handle.wait(): Promise<PtyResult>

Resolves when the remote shell exits.

handle.stream(): AsyncGenerator<Uint8Array>

Async iterator over raw output chunks — for when you want to drive the stream manually instead of via onData:
Don’t mix onData and stream() on the same handle; they consume the same underlying connection.

PtyResult

Low-level API (by pid)

When you don’t hold a PtyHandle, use the module-level methods:

Example: wire a sandbox PTY into xterm.js

That’s the full wiring for a browser terminal talking to a sandbox PTY — every keystroke round-trips through sendInput, every output byte comes back via onData, every pane resize fires TIOCSWINSZ inside the sandbox.