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 whosepid identifies the PTY.
Send input
Send input to a running PTY by itspid. The data is raw bytes.
Resize a PTY
Callresize when the terminal window changes size.
Connect to a running PTY
Connect to a PTY that is already running by itspid. 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