Skip to main content
The simplest possible PTY example. Create a sandbox, open a PTY session, send a few commands as raw keystrokes, resize the terminal mid-session, and exit cleanly. Everything uses the sync API and runs without a local TTY (no raw-mode needed).

What you’ll learn

  • Opening a PTY with sbx.pty.create() and the on_data callback
  • Sending keystrokes with handle.send_stdin()
  • Resizing mid-session with handle.resize(PtySize(...))
  • Waiting for a clean exit with handle.wait()

Prerequisites

Also install the SDK if you haven’t:

Code walkthrough

Create a sandbox and open a PTY at 120x30. The on_data callback writes every chunk straight to local stdout as it arrives:
Send a few commands. A short sleep between sends gives the shell time to print output before the next command arrives:
isatty() returns True because this is a real PTY, not a piped exec. stty size prints 30 120 matching the size we requested. Resize the terminal to 100x40 and verify:
Exit the shell and collect the result:

Running it

Expected output

The key takeaway: the remote shell saw a real PTY (isatty() = True) and stty size updated after handle.resize() without reconnecting.

Full source

See cookbook/examples/pty-repl/main.py in the repo.