# node:child_process

> How Elide supports Node's `child_process`: spawn, exec, execFile and their Sync forms, fork() with IPC between Elide scripts, and sandbox flags.

`node:child_process` provides [Node's process APIs](https://nodejs.org/api/child_process.html): `spawn`, `exec`,
`execFile`, their `Sync` forms, `fork`, and `ChildProcess`.

## Example

```js
// child.mjs
import { execFile, execFileSync } from "node:child_process";
import { promisify } from "node:util";

console.log(execFileSync("echo", ["hello"], { encoding: "utf8" }).trim());

const { stdout, stderr } = await promisify(execFile)("sh", ["-c", "echo out; echo err >&2"]);
console.log(JSON.stringify({ stdout, stderr }));

try {
  execFileSync("sh", ["-c", "exit 3"]);
} catch (error) {
  console.log("exit status", error.status);
}
```

`elide run child.mjs` prints:

```text
hello
{"stdout":"out\n","stderr":"err\n"}
exit status 3
```

## Differences from Node

- `fork()` starts another Elide script; `child.send()` and `process.send()` exchange `message` events.
- `process.execPath` runs Elide: `execFileSync(process.execPath, ["--snippet", 'process.stdout.write("hi")'])`.
- `--allow-run` and `--deny-run` apply under the [sandbox](https://elide.help/docs/sandbox).

## Samples

- [Sandboxed subprocess](https://elide.help/docs/code-samples#sandboxed-subprocess)

<!-- api-reference:start ab2926d28c89 -->
## Reference

**Status:** Full · Not measured · since 1.1.0

### Exports

| Export | Kind | Status | Notes |
| --- | --- | --- | --- |
| `exec()`, `execSync()` | function | Full | Executes a command in a shell |
| `execFile()`, `execFileSync()` | function | Full | Executes a file without a shell |
| `spawn()`, `spawnSync()` | function | Full | Spawns a new process using the given command |
| `fork()` | function | Full | Spawns a new Node.js process using the given module path |
<!-- api-reference:end -->
