Skip to main content
child_process runs OS subprocesses. POSIX only (macOS and Linux), max 8 concurrent children. Everything is evented on the main loop — no extra threads — and it is safe to use alongside http.serve, fetch, or Worker.

Permissions

Starting any child needs --allow-run for the executable:
Scopes come in two forms:
  • Matching is exact and case-sensitive. There are no globs.
  • A bare-name scope ignores the path entirely: --allow-run=git also permits /tmp/evil/git. If you need path confinement, use an absolute scope and invoke the program by path.
  • An absolute scope only matches an explicit path. spawn("git", ...) never matches --allow-run=/usr/bin/git; use spawn("/usr/bin/git", ...) (or a bare-name scope).
  • Absolute scopes are canonicalized at launch; symlinks are resolved, and the program is canonicalized again when spawned. A symlink that resolves outside the scope is denied.
  • --allow-run does not need --allow-read for the executable. The OS loader opens it; the run grant is what controls the launch.
Denial is synchronous and uses the standard shape:
execSync reports its own API name:

exec always needs /bin/sh

exec and execSync run /bin/sh -c "<your command>". The only program checked is the shell, so every exec call needs a run scope for /bin/sh (or the bare name sh):
Permitting /bin/sh permits any command string — the shell interprets whatever you pass, including redirections and pipelines. If you want to restrict which programs run, use spawn with an explicit executable and arguments instead of exec.
Security caveat: a child is a separate OS process. It is not bound by the parent’s --allow-read / --allow-write / --allow-net scopes and can access anything the OS user can. Its cwd and env options are likewise not permission-gated. run and ffi are trust-equivalent to full access; use them only for code and programs you would trust with the whole process.
Full model: Permissions.

Quick look

exec needs the shell grant; spawn needs the program’s name or path.

Reference

Options (all functions): cwd (string), env (object — replaces the environment), maxBuffer (bytes per stream, default 1 MB, Infinity allowed). spawn additionally takes stdio: "pipe" | "inherit" (default "pipe"; "inherit" passes ff’s stdio through and captures nothing). cwd and env affect only the child. They do not widen or narrow ff’s permission scopes.

The Child object

For spawn, the returned object exposes the captured results: spawn results land on the object at the same moment wait() resolves:
or, with a bare-name scope, --allow-run=echo.

Examples

Capture output and check the exit code:
Run without a shell (no quoting worries):
Stop a long-running child:
Synchronous use in scripts:

Caveats

  • No streams or events. There is no child.stdin, no on("data"), and no spawnSync in this version — output is captured and delivered through wait() / the returned promise. Writing to stdin is not supported yet.
  • A running child keeps ff alive — the process won’t exit until its children are reaped (let them finish, or kill() them). process.exit() bypasses this.
  • Children are not killed when ff exits — same as Node. Call kill() yourself for anything that must not outlive the runtime.
  • wait() waits for the pipes to close, so a grandchild that inherits stdout/stderr delays resolution (Node’s close event behaves the same).
  • exec output is decoded as UTF-8; binary output may not round-trip.
  • process.stats().child exposes spawned / truncated / outHeap counters for watching subprocess activity.
  • Child permissions are the OS user’s. --allow-run is a launch gate, not a sandbox. Once started, the child can open any file, socket, or environment the OS allows, regardless of the parent’s scopes.

See also