Bun.spawn() in Bun

From the Bun cheat sheet ยท Shell & Child Processes ยท verified Jul 2026

Bun.spawn()

Spawn child processes with fine-grained control

typescript
// Run a command
const proc = Bun.spawn(["echo", "Hello"]);
await proc.exited; // Wait for completion

// Capture stdout
const proc = Bun.spawn(["ls", "-la"], {
  stdout: "pipe",
});
const output = await new Response(proc.stdout).text();
๐Ÿ’ก Bun.spawn() takes an array of args โ€” no shell interpretation, safe from injection
โšก Use Bun.spawnSync() for quick blocking commands like git status
๐Ÿ“Œ Set stdout: "pipe" to capture output โ€” then read it as a Response stream
๐ŸŸข Prefer Bun.$ for simple commands and Bun.spawn() for fine-grained process control
spawnprocesschild

More Bun tasks

Back to the full Bun cheat sheet