Skip to content

Stream command output

Pass output callbacks to commands.run when the application should process data before the command finishes.

mjs
import { Sandbox } from "@abox-dev/sdk";

const sandbox = await Sandbox.create();

try {
  await sandbox.commands.run("printf 'first\\n'; sleep 1; printf 'second\\n'", {
    onStdout: (data) => process.stdout.write(data),
    onStderr: (data) => process.stderr.write(data),
  });
} finally {
  await sandbox.kill();
}

Each callback receives a chunk, not necessarily a complete line. Write chunks as they arrive or buffer them if you need line-oriented processing.

commands.run still resolves only after the command exits and returns the full result. Use a background command when the caller must continue immediately.