Skip to content

Add Sandbox.execStream() and abort signals; prepare 2.2.0 for npm - #70

Merged
ats3v merged 6 commits into
mainfrom
sandbox-exec-stream
Nov 12, 2026
Merged

ats3v merged 6 commits into
mainfrom
sandbox-exec-stream

Conversation

@ats3v

@ats3v ats3v commented Nov 11, 2026

Copy link
Copy Markdown
Member

Adds streaming to sandbox exec and gets the package ready for npm. npm still has only 2.0.2: the 2.1.0 publish job failed, so the Sandbox API has not shipped there yet.

  • sb.execStream(cmd, ...args, options?) yields { type: "stdout" | "stderr", data } while the command runs, then one { type: "exit", returncode }. exec() folds the same stream and behaves as before.
  • { signal } on exec() and execStream(): aborting throws the signal's reason. The command keeps running in the sandbox until it exits or reaches its timeout.
  • Packaging: a jest mock no longer ships in dist/, the typesript keyword is fixed, and the version is 2.2.0.
  • Publishing: deploy.yml moves to npm trusted publishing (needs npm 11.5.1+, hence Node 24) and keeps NPM_TOKEN as the fallback. The logs of the failed 2.1.0 job have expired, so it is unknown whether the current token still works; adding the trusted publisher on npmjs.com before the release (steps in RELEASE.MD) avoids depending on it.

Test results

The packed tarball, installed in a fresh project and run against the live API:

Check Result
Script printing once a second chunks 1.06 / 0.96 / 1.09 s apart, then exit with the script's code
Abort mid-stream the loop throws AbortError at once
AbortSignal.timeout(1500) on exec() TimeoutError after 1.50 s
break out of the loop of a 20 s command returns in 0.70 s, and the next exec() works
Command running past its timeout the output so far, then SandboxExecError
3 MB output, multi-byte output intact
require, import, and tsc --strict under nodenext / bundler / node10 pass
README snippet and examples/sandbox-quickstart.ts run as written
Unit tests on Node 22 and 24 (CI covers 16 / 18 / 20; the publish job now uses 24) pass

Not covered: the publish job itself, which runs only on a release. npm publish --dry-run passes.

After yielding the exit event, the exec generator keeps reading until the
response ends. An abort in that window made the loop, or exec(), throw the
signal's reason for a command that had already finished. Once the exit
event has been delivered, an abort now ends the stream normally.
…he command

Like aborting, leaving the loop early (break, return or an exception) only
closes the connection: the command keeps running until it exits or reaches
its timeout, 60 seconds by default.

@bo-deepinfra bo-deepinfra 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. exec() folding execStream()'s events keeps its old behaviour, including the missing-return-code error. The abort handling is right: the caller's reason wins over the transport error, and an abort after the exit event ends the stream cleanly. Breaking out of the loop destroys the response body, and the tests cover all three cases. On the workflow: checkout@v7 and setup-node@v7 exist, id-token: write is set, and repository.url matches this repo, which trusted publishing needs. NPM_TOKEN stays as the fallback.

@ats3v
ats3v merged commit f18168f into main Nov 12, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants