Skip to content

fix(sdk): support sending input through the PTY handle - #1502

Open
mishushakov wants to merge 5 commits into
mainfrom
mishushakov/pty-send-stdin-error
Open

mishushakov wants to merge 5 commits into
mainfrom
mishushakov/pty-send-stdin-error

Conversation

@mishushakov

@mishushakov mishushakov commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Calling send_stdin/sendStdin on the handle returned by pty.create()/pty.connect() raised "Sending stdin is not supported for this command handle". A PTY has no stdin; input goes to the terminal. So instead of wiring up stdin, this PR adds a dedicated send_input/sendInput to the handle for PTYs, across the JS and Python (sync + async) SDKs:

  • Handle: new handle.sendInput() / handle.send_input(), available only on PTY handles. Calling send_stdin/sendStdin on a PTY handle now raises an error that points to send_input(). Calling send_input on a regular command handle points to send_stdin().
  • Python module: sandbox.pty.send_input() is added (matching the JS sandbox.pty.sendInput()). sandbox.pty.send_stdin() is kept as a deprecated alias.
  • JS module: sandbox.pty.sendInput() stays the canonical method (no rename).
  • PTY input methods now also accept str, encoded as UTF-8.

Usage

terminal = sandbox.pty.create(size=PtySize(rows=24, cols=80))
terminal.send_input(b"whoami\n")            # on the handle
sandbox.pty.send_input(terminal.pid, "exit\n")  # module method, str works too
terminal.wait(on_pty=lambda data: print(data.decode(), end=""))
const terminal = await sandbox.pty.create({ cols: 80, rows: 24, onData: () => {} })
await terminal.sendInput('whoami\n')                 // on the handle
await sandbox.pty.sendInput(terminal.pid, 'exit\n')  // module method, string works too

Tests

  • Unit tests (JS commandHandle.test.ts, Python test_command_handle.py) cover input routing on PTY handles and the error messages that point to the right method.
  • Integration tests for sync/async Python and JS are updated to send_input/sendInput, with handle-level and str-input cases, plus a Python test for the deprecated pty.send_stdin alias.

🤖 Generated with Claude Code

Wire up `handle_send_stdin`/`handleSendStdin` on the handle returned by
`pty.create()`/`pty.connect()` across the JS and Python (sync + async)
SDKs, so `handle.send_stdin(...)`/`handle.sendStdin(...)` works the same
as for regular command handles instead of raising "Sending stdin is not
supported for this command handle." PTY input methods now also accept
`str`, encoding it as UTF-8.

In the JS SDK, `pty.sendStdin()` is added as the canonical PTY input
method to mirror `commands.sendStdin()`, with `pty.sendInput()` kept as
a deprecated alias.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e3d87e7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@e2b/python-sdk Patch
e2b Patch
@e2b/code-interpreter-python Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cursor

cursor Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

PR Summary

Low Risk
Additive SDK surface and clearer errors; send_stdin remains as a deprecated Python alias.

Overview
PTY handles from pty.create() / pty.connect() can send keyboard input via sendInput() / send_input() on the handle, not only through PID-based sandbox.pty.sendInput(). sendStdin() / send_stdin() on a PTY handle now errors with a message to use the PTY input method instead. PTY input APIs accept str (UTF-8). Python adds sandbox.pty.send_input(); send_stdin() is a deprecated alias to it.

Reviewed by Cursor Bugbot for commit e3d87e7. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from 3b97b0d. Download artifacts from this workflow run.

JS SDK (e2b@2.64.1-mishushakov-pty-send-stdin-error.0, with @e2b/dockerfile-utils@0.1.3-mishushakov-pty-send-stdin-error.0):

npm install ./e2b-dockerfile-utils-0.1.3-mishushakov-pty-send-stdin-error.0.tgz ./e2b-2.64.1-mishushakov-pty-send-stdin-error.0.tgz

CLI (@e2b/cli@2.24.1-mishushakov-pty-send-stdin-error.0):

npm install ./e2b-cli-2.24.1-mishushakov-pty-send-stdin-error.0.tgz

Code Interpreter JS SDK (@e2b/code-interpreter@2.9.2-mishushakov-pty-send-stdin-error.0):

npm install ./e2b-code-interpreter-2.9.2-mishushakov-pty-send-stdin-error.0.tgz

Desktop JS SDK (@e2b/desktop@2.5.1-mishushakov-pty-send-stdin-error.0):

npm install ./e2b-desktop-2.5.1-mishushakov-pty-send-stdin-error.0.tgz

Python SDK (e2b==2.64.0+mishushakov.pty.send.stdin.error, with e2b-dockerfile-utils==0.1.2+mishushakov.pty.send.stdin.error):

pip install ./e2b_dockerfile_utils-0.1.2+mishushakov.pty.send.stdin.error-py3-none-any.whl ./e2b-2.64.0+mishushakov.pty.send.stdin.error-py3-none-any.whl

Code Interpreter Python SDK (e2b-code-interpreter==2.11.10+mishushakov.pty.send.stdin.error):

pip install ./e2b_code_interpreter-2.11.10+mishushakov.pty.send.stdin.error-py3-none-any.whl

Desktop Python SDK (e2b-desktop==2.7.2+mishushakov.pty.send.stdin.error):

pip install ./e2b_desktop-2.7.2+mishushakov.pty.send.stdin.error-py3-none-any.whl

claude[bot]

This comment was marked as resolved.

Addresses PR review: the CLI was the one internal consumer still calling
the now-deprecated `pty.sendInput`, which would emit a self-inflicted
deprecation warning. Switch it to the canonical `pty.sendStdin` (identical
behavior, the alias just delegates).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mishushakov
mishushakov requested a review from huv1k June 30, 2026 11:26
@mishushakov
mishushakov enabled auto-merge (squash) June 30, 2026 13:15
@linear-code

linear-code Bot commented Jul 14, 2026

Copy link
Copy Markdown

SDK-221

@jakubno
jakubno removed request for huv1k and jakubno July 29, 2026 07:01
…stdin-error

# Conflicts:
#	packages/python-sdk/e2b/sandbox_async/commands/pty.py
#	packages/python-sdk/e2b/sandbox_sync/commands/pty.py
@ValentaTomas

Copy link
Copy Markdown
Member

My reluctance here is that we don't feed the input to the process stdin, so I didn't want to name it stdin. Also the output is not called stdout (the same case), so the symmetry is already broken.

Might make sense to have both for compatibility, but does not feel very clean then.

@mishushakov

Copy link
Copy Markdown
Member Author

@ValentaTomas I would settle on one name, in that case as far as I understand, sendInput would be the correct one?

PTYs have no stdin, so PTY input is exposed as sendInput/send_input:
- JS: keep pty.sendInput as the canonical method (drop the sendStdin
  rename), accept strings, add CommandHandle.sendInput for PTY handles.
- Python: add pty.send_input, keep pty.send_stdin as a deprecated alias,
  add CommandHandle.send_input for PTY handles (sync + async).
- send_stdin/sendStdin on a PTY handle now points to send_input/sendInput.
- CLI takes main's streamInput-based terminal input.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mishushakov mishushakov changed the title fix(sdk): support sending stdin through the PTY command handle fix(sdk): support sending input through the PTY handle Nov 13, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 2 flags

Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants