Skip to main content
This cookbook proves that the sandbox PTY is a fully capable xterm-256color terminal. Every byte the shell emits — including raw ANSI escape sequences — streams back through the SSE pipe and renders on your local terminal unchanged.

What you’ll learn

  • Querying $TERM, tput colors, and tty inside the sandbox
  • Rendering the 16-colour and 256-colour ANSI palettes
  • Text styles: bold, underline, reverse, blink
  • Cursor save/restore and absolute positioning
  • Using tput abstractions alongside raw escape codes
  • Bracketed-paste toggle and ncurses TTY detection

Prerequisites

Code walkthrough

The script opens a PTY and drives nine mini-tests through handle.send_stdin(). A small helper sends a command and sleeps briefly to let output flush:

1. TERM value + tput

2. ANSI 16-colour palette

Eight background-coloured cells, one per ANSI base colour.

3. Text styles

4. 256-colour palette

A 16x16 grid of \e[48;5;Nm background cells covering the full 256-colour cube.

5. Cursor save/restore + absolute move

The cursor jumps to row 5 col 40, prints a label, then restores back.

6-9. tput abstractions, bracketed paste, TTY detection

The remaining sections use tput setaf, toggle bracketed-paste mode, and confirm test -t 0 reports stdin as a TTY with stty size matching the requested dimensions.

Running it

Use an xterm-compatible terminal (iTerm2, Alacritty, Kitty, or any tmux pane) so the ANSI output renders correctly.

How it works

Every escape sequence is generated by the shell running inside the sandbox. The bytes travel through the SSE stream to on_data, which writes them directly to your local stdout.buffer. Your terminal emulator does the actual rendering — the SDK never interprets or strips ANSI codes.

Full source

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