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).Documentation Index
Fetch the complete documentation index at: https://docs.declaw.ai/llms.txt
Use this file to discover all available pages before exploring further.
What you’ll learn
- Opening a PTY with
sbx.pty.create()and theon_datacallback - 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. Theon_data callback
writes every chunk straight to local stdout as it arrives:
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:
Running it
Expected output
isatty() = True)
and stty size updated after handle.resize() without reconnecting.
Full source
Seecookbook/examples/pty-repl/main.py in the repo.