Skip to main content
This cookbook demonstrates the full stdio API surface through six self-contained demos. Each one starts a process with an open stdin pipe, sends data, and reads the response.

What you’ll learn

  • Sending stdin and receiving stdout via sandbox.stdio.start(cmd)
  • Separate on_stdout and on_stderr callbacks
  • Multi-round interactive conversations (read-echo loop)
  • Iterator / stream protocol for consuming output
  • Closing stdin to signal EOF (proc.close_stdin())
  • Custom environment variables and working directory
  • Killing a long-running process (proc.kill())

Prerequisites

Install the SDK:

1. Basic echo (cat)

Start cat, send a line, close stdin, and read the echoed output.

2. Stdout and stderr callbacks

Receive stdout and stderr on separate callbacks.

3. Multi-round interactive conversation

Send multiple lines to a process that reads in a loop.

4. Line counting with EOF

Send lines to wc -l and close stdin so it sees EOF and reports.

5. Environment variables and working directory

Pass env vars and set the working directory.

6. Kill a long-running process

Start a process, wait briefly, kill it, and read the exit code.

Full runnable examples

Complete self-contained scripts with all six demos and cleanup are available in the SDK repositories. Install the SDK (pip install declaw or npm install @declaw/sdk) and run the example directly.