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:
- Matching is exact and case-sensitive. There are no globs.
- A bare-name scope ignores the path entirely:
--allow-run=gitalso 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; usespawn("/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-rundoes not need--allow-readfor the executable. The OS loader opens it; the run grant is what controls the launch.
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):
/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.
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:
--allow-run=echo.
Examples
Capture output and check the exit code:Caveats
- No streams or events. There is no
child.stdin, noon("data"), and nospawnSyncin this version — output is captured and delivered throughwait()/ 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 inheritsstdout/stderrdelays resolution (Node’scloseevent behaves the same).execoutput is decoded as UTF-8; binary output may not round-trip.process.stats().childexposesspawned/truncated/outHeapcounters for watching subprocess activity.- Child permissions are the OS user’s.
--allow-runis 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
- Permissions — flags, scopes, denial contract
- Process — argv, env, cwd, exit
- API overview — every injected global
- Limitations — every hard cap