feat(sdk): expose resize_tty in Python SDK and add AI agent guide#220
feat(sdk): expose resize_tty in Python SDK and add AI agent guide#220DorianZheng merged 6 commits intomainfrom
Conversation
Provide a persistent interactive terminal example for installing Claude Code and document it in the examples README. Co-authored-by: Cursor <[email protected]>
Rename file to remove "ubuntu" misnomer, remove unused BoxOptions, consolidate imports, and improve documentation. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…on guide Add resize_tty(rows, cols) binding to PyExecution (Rust) and SyncExecution (Python sync wrapper), enabling terminal resizing for TTY-enabled executions without the stty stdin workaround. Also add a comprehensive AI agent integration guide covering configuration, concurrency, timeouts, security, and file transfer patterns. Closes #218 items #4 and #6. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR extends the BoxLite Python SDK to support resizing PTY/TTY-backed executions via a new Execution.resize_tty(rows, cols) API, and adds documentation aimed at AI-agent integration patterns (including timeouts, concurrency, security, and terminal sizing).
Changes:
- Add
resize_tty(rows, cols)to the native PythonExecutionbinding and the sync wrapper. - Document
resize_ttyin Python SDK docs and add a new AI agent integration guide. - Add unit + integration tests for the new API surface and behavior, plus a new interactive example script.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
sdks/python/src/exec.rs |
Adds the Rust→PyO3 binding for Execution.resize_tty() |
sdks/python/boxlite/sync_api/_execution.py |
Adds sync wrapper method SyncExecution.resize_tty() |
sdks/python/README.md |
Documents resize_tty in the Execution method list |
docs/reference/python/README.md |
Adds resize_tty to the Python reference methods table |
docs/guides/ai-agent-integration.md |
New AI agent integration guide (timeouts, concurrency, security, resizing) |
docs/guides/README.md |
Adds a cross-link to the new AI agent guide |
sdks/python/tests/test_exec.py |
Adds API surface checks for resize_tty export |
sdks/python/tests/test_resize_tty.py |
New async integration tests for resize behavior |
sdks/python/tests/test_sync_api.py |
Adds sync integration tests for resize behavior |
examples/python/interactive_claude_example.py |
New interactive Claude Code install terminal example |
examples/python/README.md |
Adds the new interactive Claude example to the examples index |
Comments suppressed due to low confidence (1)
sdks/python/tests/test_exec.py:152
- This import of module boxlite is redundant, as it was previously imported on line 10.
import boxlite
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| box = shared_sync_runtime.create(boxlite.BoxOptions(image="alpine:latest")) | ||
| execution = box.exec("sh", tty=True) | ||
|
|
||
| # Should not raise | ||
| execution.resize_tty(40, 120) | ||
|
|
There was a problem hiding this comment.
SyncBox.exec() (used by box here) does not accept a tty keyword argument (its signature is exec(cmd, args=None, env=None)), so this call will raise TypeError and the test will fail. Either extend the sync API to support tty (and forward it to the native async Box.exec(..., tty=...)) or adjust the test to create a TTY execution through an API that actually supports it.
| box = shared_sync_runtime.create(boxlite.BoxOptions(image="alpine:latest")) | ||
| execution = box.exec("sh", tty=True) | ||
|
|
||
| # Small terminal | ||
| execution.resize_tty(24, 80) | ||
| # Large terminal | ||
| execution.resize_tty(100, 300) | ||
| # Minimum dimensions | ||
| execution.resize_tty(1, 1) |
There was a problem hiding this comment.
Same issue as above: SyncBox.exec() does not currently accept tty=True, so this test will error before exercising resize_tty. Add tty: bool = False to the sync exec wrapper (and pass it through) or avoid using tty in sync tests until the API supports it.
examples/python/README.md
Outdated
| ### interactive_claude_ubuntu_example.py | ||
| Interactive terminal for Claude Code: | ||
| - Persistent box with a bash shell | ||
| - Install Claude Code directly in the terminal | ||
| - Reuse the same box across sessions | ||
|
|
There was a problem hiding this comment.
This section header and description reference interactive_claude_ubuntu_example.py, but the added example file in this PR is named interactive_claude_example.py. Update the README section title/filename (or rename the script) so users can find and run the example.
| | `seccomp_enabled` | `bool` | Syscall filtering (Linux only) | | ||
| | `max_open_files` | `int \| None` | Limit open file descriptors | | ||
| | `max_file_size` | `int \| None` | Maximum file size in bytes | | ||
| | `max_processes` | `int \| None` | Maximum number of processes | | ||
| | `max_memory` | `int \| None` | Maximum virtual memory in bytes | | ||
| | `max_cpu_time` | `int \| None` | Maximum CPU time in seconds | | ||
| | `network_enabled` | `bool` | Allow network access from sandbox | | ||
| | `close_fds` | `bool` | Close inherited file descriptors | | ||
|
|
There was a problem hiding this comment.
SecurityOptions.network_enabled is documented in the Python bindings as “macOS only” (see sdks/python/src/options.rs field doc). This guide currently presents it as a general network isolation switch; please clarify platform support/behavior (and what to do on Linux) to avoid misleading security guidance.
| - `resize_tty(rows: int, cols: int) -> None` | ||
| Resize PTY terminal window (async). Only works with TTY-enabled executions. | ||
|
|
There was a problem hiding this comment.
While updating this Execution docs section, note that the examples in this README call box.exec("python", "-c", ...) using varargs. The native Box.exec binding is exec(command, args=None, env=None, tty=False) (args must be a list), so the varargs form is misleading and can behave incorrectly (e.g., splitting strings into characters). Please update the examples/signature description in this section to match the actual API.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
- Resolve merge conflict in examples/python/README.md (keep main's version) - Add tty parameter to SyncBox.exec() to match native Box.exec() API - Add macOS-only annotation for network_enabled in AI agent guide - Fix missing blank line before Resource Limits heading in guide - Remove redundant boxlite import in test_exec.py Co-Authored-By: Claude Opus 4.6 <[email protected]>
Summary
resize_tty(rows, cols)in Python SDK — adds Rust binding (PyExecution) and sync wrapper (SyncExecution), enabling terminal resizing for TTY-enabled executions without thesttystdin workaroundImplements #218 items #4 and #6.
Changed files
sdks/python/src/exec.rsresize_ttymethod toPyExecutionsdks/python/boxlite/sync_api/_execution.pyresize_ttytoSyncExecutionsdks/python/README.mdresize_ttyin Execution methodsdocs/reference/python/README.mdresize_ttyto methods tabledocs/guides/ai-agent-integration.mddocs/guides/README.mdsdks/python/tests/test_exec.pysdks/python/tests/test_resize_tty.pysdks/python/tests/test_sync_api.pyTest plan
cargo check -p boxlite-python— compiles without errorscargo fmt --check -p boxlite-python— formatting passesmake dev:python— full build succeedspytest tests/test_exec.py— 29/29 passed (includestest_execution_has_resize_tty)test_resize_tty.py,test_sync_api.pyresize tests) — require VM environment🤖 Generated with Claude Code