Skip to content

2.2.0 | Sandbox exec streaming

Latest

Choose a tag to compare

@ats3v ats3v released this 12 Nov 12:01
4fdf685

New: streaming exec

execStream() yields a command's output while it runs, then its exit code:

import { Sandbox } from "deepinfra";

const sb = await Sandbox.create({ plan: "nano", timeout: "5m" });
const countdown = "for i in 3 2 1; do echo $i; sleep 1; done";
for await (const event of sb.execStream("bash", "-c", countdown)) {
  if (event.type === "stdout") process.stdout.write(event.data);
  else if (event.type === "stderr") process.stderr.write(event.data);
  else console.log("exit code", event.returncode);
}
await sb.terminate();
  • execStream(cmd, ...args, options?) yields { type: "stdout" | "stderr", data } chunks as they arrive, then one { type: "exit", returncode }. exec() still returns the whole output at once.
  • exec() and execStream() take an AbortSignal ({ signal }). Aborting makes the pending call or loop throw the signal's reason.
  • Neither aborting nor leaving the loop early stops the command: it keeps running in the sandbox until it exits or reaches its timeout (60 seconds by default).

See the Sandboxes section of the README.

Other changes

  • 2.1.0 was tagged but never published to npm, so this is the first npm release with the Sandbox API.
  • The published package no longer includes a test mock.
  • Releases are now staged on npm through trusted publishing and go live only after a maintainer approves them.

Full diff: 2.1.0...2.2.0