fix(js-sdk): use commands.run in Sandbox.getHost() example#1531
Conversation
The getHost() JSDoc @example called sandbox.commands.exec(), which is not a method on the Commands class (it exposes run()), so copy-pasting the snippet threw "TypeError: sandbox.commands.exec is not a function". Switch it to sandbox.commands.run(), matching the sibling example in the same file and the Python SDK. Documentation only, no behavior change. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 61d2c56 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 61d2c5620f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| * const sandbox = await Sandbox.create() | ||
| * // Start an HTTP server | ||
| * await sandbox.commands.exec('python3 -m http.server 3000') | ||
| * await sandbox.commands.run('python3 -m http.server 3000') |
There was a problem hiding this comment.
Run the server example in the background
When users copy-paste this getHost() example, commands.run still does not reach the getHost line because Commands.run waits for completion unless opts.background is true (packages/js-sdk/src/sandbox/commands/index.ts lines 408-423). python3 -m http.server is a long-lived process, so this await will hang or time out instead of starting a server and returning a host; the existing HTTP-server tests use { background: true } for this case.
Useful? React with 👍 / 👎.
|
@anxkhn please fix the codex comment and in any other places |
The JSDoc
@exampleon the publicSandbox.getHost()method callssandbox.commands.exec(...), but theCommandsclass has noexecmethod. Itexposes
run. Copy-pasting the documented snippet therefore throws:Where
packages/js-sdk/src/sandbox/index.ts, in thegetHost()doc comment:The
Commandsclass (packages/js-sdk/src/sandbox/commands/index.ts) exposeslist,sendStdin,closeStdin,kill,connect, andrun(fourrunoverloads), plus a private
start. There is noexec. The correct method hereis
run, which is what every other example already uses, including the sibling@examplein this same file (thecommands.run(...)snippet a few methods up)and both Python SDK mirrors (
get_hostinsandbox_sync/main.pyandsandbox_async/main.pyalready usecommands.run).Fix
One token,
exec->run: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_hostexamples already usecommands.runcorrectly,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
@examplecorrection with no runtime code path to exercise, soit 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 suchas #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.execno longer appears anywhere in the SDK source, and
commands.runmatches theCommandsclass and the sibling examples.Offline gates run locally (Node 20, pnpm 9.15.5):
A changeset (
e2b, patch) is included.Linked issues
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)
pnpm run format-prettier --checkclean on the changed filepnpm run lint- oxlint clean (exit 0)pnpm run typecheck- tsc --noEmit clean (exit 0)pnpm run build- tsc + tsup clean.changeset/fix-gethost-example-command.md(e2b: patch)fix(js-sdk): ..., reusesjs-sdkscope)@example; see Tests section for precedent)@cla-boton the PR after opening (as on prior PRs fix(js-sdk): don't treat "detached" in a branch name as a detached HEAD #1518 / fix(python-sdk): strip colon-separated SGR escape codes in build logs #1519 / fix(python-sdk): percent-encode git credentials in with_credentials #1507)