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:
onData and stream() on the same handle; they consume the
same underlying connection.
PtyResult
Low-level API (by pid)
When you don’t hold aPtyHandle, use the module-level methods:
Example: wire a sandbox PTY into xterm.js
sendInput, every output byte
comes back via onData, every pane resize fires TIOCSWINSZ inside
the sandbox.