Skip to content

fix(js-sdk): use commands.run in Sandbox.getHost() example (#1531)#1550

Open
mishushakov wants to merge 1 commit into
mainfrom
fix/js-sdk-gethost-example-base
Open

fix(js-sdk): use commands.run in Sandbox.getHost() example (#1531)#1550
mishushakov wants to merge 1 commit into
mainfrom
fix/js-sdk-gethost-example-base

Conversation

@mishushakov

Copy link
Copy Markdown
Member

The JSDoc @example on the public Sandbox.getHost() method calls sandbox.commands.exec(...), but the Commands class has no exec method. It
exposes run. Copy-pasting the documented snippet therefore throws:

TypeError: sandbox.commands.exec is not a function

Where

packages/js-sdk/src/sandbox/index.ts, in the getHost() doc comment:

/**
 * ...
 * @example
 * ```ts
 * const sandbox = await Sandbox.create()
 * // Start an HTTP server
 * await sandbox.commands.exec('python3 -m http.server 3000')  // <- no such method
 * // Get the hostname of the HTTP server
 * const serverURL = sandbox.getHost(3000)
 * ```
 */

The Commands class (packages/js-sdk/src/sandbox/commands/index.ts) exposes
list, sendStdin, closeStdin, kill, connect, and run (four run
overloads), plus a private start. There is no exec. The correct method here
is run, which is what every other example already uses, including the sibling
@example in this same file (the commands.run(...) snippet a few methods up)
and both Python SDK mirrors (get_host in sandbox_sync/main.py and sandbox_async/main.py already use commands.run).

Fix

One token, exec -> run:

- await sandbox.commands.exec('python3 -m http.server 3000')
+ await sandbox.commands.run('python3 -m http.server 3000')

Documentation only. No behavior or type change.

Parity with the Python SDK

The repo guidelines ask that SDK changes be mirrored across the JS and Python
SDKs. Here the Python get_host examples already use commands.run correctly,
so this defect exists only in the JS SDK doc comment and no Python change is
needed to reach parity.

Tests

This is a JSDoc @example correction with no runtime code path to exercise, so
it adds no test, matching the repo's existing precedent for documentation-only
fixes (e.g. .changeset/sandbox-list-docstring.md, and merged doc-fix PRs such
as #1511 / #1500 / #1260, none of which added a regression test). Correctness is
that the example now names the real public API: after the change, commands.exec
no longer appears anywhere in the SDK source, and commands.run matches the
Commands class and the sibling examples.

Offline gates run locally (Node 20, pnpm 9.15.5):

pnpm --filter e2b run lint        # oxlint, clean
pnpm --filter e2b run typecheck   # tsc --noEmit, clean
pnpm --filter e2b run build       # tsc + tsup, ESM/CJS/DTS built
prettier --check src/sandbox/index.ts  # clean

A changeset (e2b, patch) is included.


Linked issues

  • None. There is no existing GitHub issue for this; it is a self-evident public
    doc-example defect (the documented snippet throws at runtime). Not filing a
    separate issue for a one-token doc fix.

Pre-flight checklist (repo AGENTS.md / CLAUDE.md gates)

The JSDoc `@example` on the public `Sandbox.getHost()` method calls
`sandbox.commands.exec(...)`, but the `Commands` class has no `exec`
method. It
exposes `run`. Copy-pasting the documented snippet therefore throws:

```
TypeError: sandbox.commands.exec is not a function
```

### Where

`packages/js-sdk/src/sandbox/index.ts`, in the `getHost()` doc comment:

```ts
/**
 * ...
 * @example
 * ```ts
 * const sandbox = await Sandbox.create()
 * // Start an HTTP server
 * await sandbox.commands.exec('python3 -m http.server 3000')  // <- no such method
 * // Get the hostname of the HTTP server
 * const serverURL = sandbox.getHost(3000)
 * ```
 */
```

The `Commands` class (`packages/js-sdk/src/sandbox/commands/index.ts`)
exposes
`list`, `sendStdin`, `closeStdin`, `kill`, `connect`, and `run` (four
`run`
overloads), plus a private `start`. There is no `exec`. The correct
method here
is `run`, which is what every other example already uses, including the
sibling
`@example` in this same file (the `commands.run(...)` snippet a few
methods up)
and both Python SDK mirrors (`get_host` in `sandbox_sync/main.py` and
`sandbox_async/main.py` already use `commands.run`).

### Fix

One token, `exec` -> `run`:

```ts
- await sandbox.commands.exec('python3 -m http.server 3000')
+ await sandbox.commands.run('python3 -m http.server 3000')
```

Documentation only. No behavior or type change.

### Parity with the Python SDK

The repo guidelines ask that SDK changes be mirrored across the JS and
Python
SDKs. Here the Python `get_host` examples already use `commands.run`
correctly,
so this defect exists only in the JS SDK doc comment and no Python
change is
needed to reach parity.

### Tests

This is a JSDoc `@example` correction with no runtime code path to
exercise, so
it adds no test, matching the repo's existing precedent for
documentation-only
fixes (e.g. `.changeset/sandbox-list-docstring.md`, and merged doc-fix
PRs such
as #1511 / #1500 / #1260, none of which added a regression test).
Correctness is
that the example now names the real public API: after the change,
`commands.exec`
no longer appears anywhere in the SDK source, and `commands.run` matches
the
`Commands` class and the sibling examples.

Offline gates run locally (Node 20, pnpm 9.15.5):

```
pnpm --filter e2b run lint        # oxlint, clean
pnpm --filter e2b run typecheck   # tsc --noEmit, clean
pnpm --filter e2b run build       # tsc + tsup, ESM/CJS/DTS built
prettier --check src/sandbox/index.ts  # clean
```

A changeset (`e2b`, patch) is included.

---

## Linked issues

- None. There is no existing GitHub issue for this; it is a self-evident
public
doc-example defect (the documented snippet throws at runtime). Not
filing a
  separate issue for a one-token doc fix.

## Pre-flight checklist (repo AGENTS.md / CLAUDE.md gates)

- [x] `pnpm run format` - `prettier --check` clean on the changed file
- [x] `pnpm run lint` - oxlint clean (exit 0)
- [x] `pnpm run typecheck` - tsc --noEmit clean (exit 0)
- [x] `pnpm run build` - tsc + tsup clean
- [x] Changeset generated - `.changeset/fix-gethost-example-command.md`
(`e2b`: patch)
- [x] Conventional Commit message (`fix(js-sdk): ...`, reuses `js-sdk`
scope)
- [ ] Test added - not applicable (doc-only `@example`; see Tests
section for precedent)
- [ ] DCO / CLA - no sign-off required by this repo; CLA is signed via
`@cla-bot`
      on the PR after opening (as on prior PRs #1518 / #1519 / #1507)

Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
@cursor

cursor Bot commented Jul 14, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Documentation and changeset only; no SDK runtime or type changes.

Overview
Fixes the Sandbox.getHost() JSDoc @example so copy-paste works: it no longer calls nonexistent sandbox.commands.exec and instead uses sandbox.commands.run('python3 -m http.server 3000', { background: true }), matching the public Commands API and letting the server run before getHost(3000).

A patch changeset for e2b documents the doc-only fix; runtime behavior is unchanged.

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

@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d7f676b

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

This PR includes changesets to release 1 package
Name Type
e2b 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

@mishushakov
mishushakov enabled auto-merge (squash) July 14, 2026 14:16
@github-actions

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from b2abe29. Download artifacts from this workflow run.

JS SDK (e2b@2.33.1-fix-js-sdk-gethost-example-base.0):

npm install ./e2b-2.33.1-fix-js-sdk-gethost-example-base.0.tgz

CLI (@e2b/cli@2.13.3-fix-js-sdk-gethost-example-base.0):

npm install ./e2b-cli-2.13.3-fix-js-sdk-gethost-example-base.0.tgz

Python SDK (e2b==2.32.0+fix.js.sdk.gethost.example.base):

pip install ./e2b-2.32.0+fix.js.sdk.gethost.example.base-py3-none-any.whl

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM — one-token doc fix, verified correct.

Extended reasoning...

Overview

Documentation-only change to the @example JSDoc on Sandbox.getHost() in packages/js-sdk/src/sandbox/index.ts, plus a changeset. Replaces a nonexistent sandbox.commands.exec(...) call with sandbox.commands.run(..., { background: true }), matching the real Commands API (confirmed run accepts a background option in commands/index.ts) and the sibling example a few methods above in the same file.

Security risks

None. No runtime code paths are touched — only a comment string.

Level of scrutiny

Minimal scrutiny warranted: single-line doc comment edit with no type or behavior change, verified against the actual Commands class API surface. Build/lint/typecheck are unaffected by definition.

Other factors

No Python SDK change needed since the Python examples already used commands.run, keeping SDK parity intact. No test needed since JSDoc examples aren't executed.

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