Skip to content

fix: align behavior and API surface between the JS and Python SDKs#1411

Open
mishushakov wants to merge 8 commits into
mainfrom
mishushakov/python-js-sdk-alignment
Open

fix: align behavior and API surface between the JS and Python SDKs#1411
mishushakov wants to merge 8 commits into
mainfrom
mishushakov/python-js-sdk-alignment

Conversation

@mishushakov

Copy link
Copy Markdown
Member

Aligns several behavioral and API-surface discrepancies between the JS and Python SDKs found during a cross-SDK audit. Python: commands.send_stdin/CommandHandle.send_stdin now accept bytes (plus request_timeout on the handle), git.reset gets a typed GitResetMode with JS-matching validation, sandbox_url is threaded through get_api_params (and the dead SandboxOpts key removed), and from_image requires both username and password when credentials are given. JS: getFullInfo was removed in favor of a single getInfo that now includes sandboxDomain (matching Python's get_info), fromImage requires both credentials, getBuildStatus defaults logsOffset to 0, getMetrics/kill short-circuit consistently in debug mode (instance + static), and requestTimeoutMs: 0 explicitly disables the request timeout. Tests were added on both sides (git-arg validation, stdin bytes, credential validation, timeout-0, connection config) and the CLI's sandbox info now uses getInfo. See the changeset for the full per-SDK list.

Usage examples

// JS: registry credentials now require both fields
Template().fromImage('registry.example.com/img:latest', { username: 'u', password: 'p' })

// JS: getInfo now exposes sandboxDomain (getFullInfo removed)
const info = await Sandbox.getInfo(sandboxId)
console.log(info.sandboxDomain)

// JS: disable the request timeout
await Sandbox.create({ requestTimeoutMs: 0 })
# Python: send raw bytes to stdin
sandbox.commands.send_stdin(cmd.pid, b"hello")

# Python: typed git reset mode (validated)
sandbox.git.reset(repo, mode="hard")

# Python: registry credentials require both fields
Template().from_image("registry.example.com/img:latest", username="u", password="p")

🤖 Generated with Claude Code

mishushakov and others added 8 commits June 9, 2026 15:05
Python: pause()/beta_pause() return bool, get_metrics no longer returns []
in debug mode, kill debug-mode handling matches JS, send_stdin accepts bytes
+ request_timeout on handle, git.reset GitResetMode + validation, sandbox_url
in get_api_params, from_image requires both credentials.

JS: getInfo() includes sandboxDomain (getFullInfo internal), fromImage requires
both credentials, getBuildStatus logsOffset defaults to 0, requestTimeoutMs 0
disables the timeout.

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

# Conflicts:
#	packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Move the debug-mode short-circuit for get_metrics into the instance method
(like kill) and implement it in the JS SDK so getMetrics() returns [] in
debug mode in both SDKs.

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

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Matches the Python SDK's single get_info. getInfo now performs the request
directly and returns SandboxInfo (incl. sandboxDomain, without the envd
access token). The envd access token is still obtained from the create/connect
responses, not getInfo.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Implement the debug-mode short-circuit for kill and get_metrics on both the
instance methods and the class/static methods (SandboxApi / _cls_*) in JS and
Python, so it applies whether called as Sandbox.kill(id) or sandbox.kill().
The API client is never constructed in debug mode (the guard runs first).

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

- JS: unit-test git.reset invalid mode + remoteAdd/remoteGet guards via a
  stub command runner (mirrors Python's test_args.py).
- JS + Python (sync + async): cover sending bytes/Uint8Array via send_stdin.

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

cursor Bot commented Jun 9, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Removing getFullInfo and changing getInfo fields is a breaking JS API change; debug short-circuits for kill/metrics can surprise callers expecting real API behavior in debug mode.

Overview
Cross-SDK mismatches are corrected in the JS and Python SDKs and the CLI. JS drops getFullInfo and folds sandbox fetch into getInfo, which now exposes sandboxDomain and no longer returns envdAccessToken; sandbox info calls getInfo instead. Debug mode skips real kill and getMetrics on both instance and static paths and returns an empty metrics list. requestTimeoutMs: 0 disables timeouts. Template.fromImage and Python from_image error when only one registry credential is set; getBuildStatus defaults logsOffset to 0.

Python stdin APIs accept bytes and optional request_timeout on handle send_stdin / close_stdin. git.reset uses exported GitResetMode with JS-aligned validation text. sandbox_url is included in get_api_params. Tests cover these behaviors on both SDKs.

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

@changeset-bot

changeset-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5389f4b

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

This PR includes changesets to release 3 packages
Name Type
e2b Patch
@e2b/python-sdk Patch
@e2b/cli 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

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from ad04efa. Download artifacts from this workflow run.

JS SDK (e2b@2.28.2-mishushakov-python-js-sdk-alignment.0):

npm install ./e2b-2.28.2-mishushakov-python-js-sdk-alignment.0.tgz

CLI (@e2b/cli@2.11.1-mishushakov-python-js-sdk-alignment.0):

npm install ./e2b-cli-2.11.1-mishushakov-python-js-sdk-alignment.0.tgz

Python SDK (e2b==2.27.0+mishushakov-python-js-sdk-alignment):

pip install ./e2b-2.27.0+mishushakov.python.js.sdk.alignment-py3-none-any.whl


// Set the registry config if provided
if (credentials) {
if (!credentials.username || !credentials.password) {

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.

probably should do credential check before doing the work above


# Set the registry config if provided
if username and password:
if username or password:

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.

slight divergence with the js here; js checks if (credentials) { this checks if username or password: so if username and password are present but falsy, JS will reject but Python will allow

}
}

static async getFullInfo(sandboxId: string, opts?: SandboxApiOpts) {

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.

maybe a reason to make major instead of minor but not end of world

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