Skip to main content
Executing Code

Output Capture

Capture or stream stdout and stderr from code running in Secure Exec.

Capture

Output is not retained unless you ask for it.

// Output is not retained unless you ask for it: "stderr" for diagnostics, "all"
// for both streams.
const captured = await execute(source, { output: { capture: "all" } });
console.log(captured.stdout); // progress: 1/2\nprogress: 2/2\n
console.log(captured.stderr); // warning: slow path\n
output.captureResult fields
"none" (default)Neither stream is retained.
"stderr"stderr. Enough for stack traces.
"all"stdout and stderr.

Captured output is bounded. When a stream exceeds the limit, the result sets stdoutTruncated or stderrTruncated.

Stream

// `onStdout` and `onStderr` stream chunks live and work with or without capture.
const decoder = new TextDecoder();
await execute(source, {
	onStdout: (chunk) => process.stdout.write(decoder.decode(chunk)),
	onStderr: (chunk) => process.stderr.write(decoder.decode(chunk)),
});

Chunks are raw bytes, so decode them before treating them as text.

Edit this page Last updated September 21, 2026