> ## Documentation Index
> Fetch the complete documentation index at: https://docs.podflare.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Fork

> Snapshot a running sandbox and spawn N copies from that state.

<ParamField path="id" type="string" required>
  Parent sandbox id.
</ParamField>

<ParamField body="n" type="int" default="1">
  Number of children to spawn. Range 1..=32.
</ParamField>

<RequestExample>
  ```bash curl theme={null}
  curl -X POST https://api.podflare.ai/v1/sandboxes/$SID/fork \
    -H 'content-type: application/json' \
    -d '{"n": 5}'
  ```

  ```python Python theme={null}
  children = parent.fork(n=5)
  try:
      results = [c.run_code(plan) for c, plan in zip(children, plans)]
  finally:
      for c in children:
          c.close()
  ```

  ```ts TypeScript theme={null}
  const children = await parent.fork(5);
  try {
    const results = await Promise.all(
      children.map((c, i) => c.runCode(plans[i]))
    );
  } finally {
    for (const c of children) await c.close();
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "children": [
      "sbx_a1ac8f28d473413585d8f4f425bcc2b1",
      "sbx_03cfbf63bb394575aefa4e6c62874998",
      "sbx_532288c716c8424cb8bb549e6ce2748b",
      "sbx_bca65926af5f4afcaa6b8f20a66845b2",
      "sbx_267b68883b41469fbda8973296767542"
    ]
  }
  ```
</ResponseExample>

## What children inherit

Each child starts from the parent's state at the moment of snapshot:

* **Python REPL state** — variables, imports, open files.
* **Filesystem** — everything written to the parent's rootfs so far.
* **Full VM memory** — page-level CoW shared with siblings; divergence
  only costs the pages a child mutates.

## Parent impact

* **Paused for \~80 ms** during snapshot. Resume is automatic.
* `exec` calls on the parent made after `fork` returns are NOT visible
  in children. Each child only sees pre-fork state.

## Timing (Hetzner EX63)

| n | Total `fork` latency |
| - | -------------------- |
| 1 | 92 ms                |
| 2 | 102 ms               |
| 5 | **101 ms**           |

Spawn cost is near-flat in N because children boot in parallel
(\~10 ms each) and the snapshot+merge happens once.

## Requirements

<Warning>
  Parent must be a pool-warm sandbox (or itself a fork child). Sandboxes
  created with custom RAM / rootfs skip the warm pool and cannot be
  forked — fork will return 500 on those.
</Warning>
