Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.superserve.ai/llms.txt

Use this file to discover all available pages before exploring further.

For long-running commands - builds, training runs, servers - pass onStdout / on_stdout and onStderr / on_stderr callbacks. Output streams over Server-Sent Events and is flushed to your callback line-by-line (or chunk-by-chunk for large bursts).
const result = await sandbox.commands.run("npm run build", {
  onStdout: (data) => process.stdout.write(data),
  onStderr: (data) => process.stderr.write(data),
  timeoutMs: 300_000,
})

console.log(`Build exited ${result.exitCode}`)
The returned result still contains the full stdout and stderr concatenated. Use it for logging or post-processing after streaming finishes.
AsyncSandbox supports the same streaming callbacks with awaitable run(). See the Sandbox reference.

Idle timeout

The SDK resets its internal idle timer on every chunk, so a slow-moving process won’t trip timeoutMs as long as it produces some output. A completely silent command still has to finish before the timeout.

Network drops

If the SSE stream ends without a terminal finished event - for example, a transient network hiccup - run() throws. Retry from the caller if you need resilience. The sandbox continues running the command even if your client disconnects; use Sandbox.connect(id) to pick it back up if you’ve stored the ID.

Capture and stream together

Streaming and sync return aren’t mutually exclusive - capture chunks for logs while also collecting the full buffer for analysis.
const logLines: string[] = []

const result = await sandbox.commands.run("./long-job.sh", {
  onStdout: (data) => {
    process.stdout.write(data)
    logLines.push(data)
  },
})

await uploadLogs(logLines.join(""))