Skip to main content

Use case

The OpenAI Agents SDK adapter routes one-shot commands through plain exec, but sometimes an agent needs a real PTY: TUI programs, progress bars, stateful shell sessions, or anything that calls isatty(). This recipe shows how to reach the full declaw PTY module from an adapter session so you get the best of both worlds — the Agents SDK tool loop and interactive terminal access when you need it.

What you’ll learn

  • Creating an OpenAI adapter session with DeclawSandboxClient
  • Reaching the PTY surface via session._inner._sbx.pty
  • Sending keystrokes, reading output, and resizing with the async API
  • Running a progress bar that would be garbled through a non-PTY pipe
  • Verifying env passthrough and shell state persistence across sends

Prerequisites

An OPENAI_API_KEY is not required for this example. It exercises the PTY surface directly without making any LLM calls.

Code walkthrough

Create the session

Open a PTY through the adapter

The adapter session exposes the underlying AsyncSandbox so you can use the PTY module directly:

Four quick probes

Clean up

Running it

Expected output

The progress bar renders as a single in-place line because the PTY supports \r cursor return — a plain exec pipe would have printed 20 separate lines.

Full source

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