Create a PTY session
You can usesandbox.pty.create() to start an interactive bash shell.
The PTY launches an interactive bash shell with
TERM=xterm-256color, so ANSI colors and escape sequences work as expected.Timeout
The timeout setting is configurable and determines how long the PTY session remains active. You can keep a PTY session open indefinitely by settingtimeoutMs: 0 in JavaScript or timeout=0 in Python. The session uses a 60-second timeout by default.
Send input to PTY
You can usesendInput() in JavaScript or send_stdin() in Python to send data to the terminal.
In JavaScript, sendInput() returns a Promise, and any terminal output is delivered through the onData callback rather than returned directly.
In Python, send_stdin() completes synchronously, and any terminal output is delivered through the on_pty callback passed to wait().
Resize the terminal
You can useresize() to notify the PTY when the user changes the terminal window size.
The cols and rows values represent the terminal dimensions in characters rather than pixels.
Disconnect and reconnect
A PTY session can remain active even after the client disconnects. You can detach from the session and reconnect to it again later with a new data handler. This can be used to recover from network interruptions, support terminal access from multiple clients, and preserve session state across reconnects.Kill the PTY
You can usekill() to terminate the PTY session.
Wait for PTY to exit
You can usewait() to block until the terminal session ends, for example when the user types exit.
Interactive terminal (SSH-like)
You can use the samesandbox.pty API described above to create a fully interactive terminal such as SSH by handling raw mode, stdin forwarding, and terminal resize events.