Skip to main content
A PTY (pseudo-terminal) is a virtual terminal interface that lets programs interact with a shell as if connected to a real terminal. Use the sandbox.pty module to create interactive terminal sessions that run commands, accept input, and can be resized while running — useful for REPLs and debuggers, interactive CLIs that prompt for input, and long-running processes you need to monitor.
Note: A PTY is identified by its process ID (pid), returned from create() on the handle. Pass that pid to send input, resize, connect, and kill. Output is delivered to a callback as raw bytes.

Create a PTY

Create a PTY and receive its output through a callback. It returns a handle whose pid identifies the PTY.

Send input

Send input to a running PTY by its pid. The data is raw bytes.

Resize a PTY

Call resize when the terminal window changes size.

Connect to a running PTY

Connect to a PTY that is already running by its pid. You can obtain running processes with sandbox.commands.list(). The returned handle receives further output through the callback.

Kill a PTY

kill terminates the PTY with SIGKILL. It returns true if the PTY was killed, or false if no PTY with that pid was found.

Interactive example

Create a PTY, send an interactive command that prompts for input, then wait for it to finish and read the exit code. In Python, wait(on_pty=...) streams output to the callback and returns the result.
Python
Last modified on August 5, 2026