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

# Fork

> Branch a running machine into an independent child machine.

Fork creates a child machine from the parent's live machine state. Parent and
child continue as independent running machines, so each can mutate files,
processes, and services without changing the other branch. Use reusable
snapshots when the captured state should be durable and restored many times
later.

## What state changes

* A new child machine starts from the parent's current state.
* Parent and child receive separate machine IDs and routing credentials.
* Later filesystem and process changes diverge between the two machines.

## Usage

<CodeGroup>
  ```python Python SDK theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  from nullspace import Machine

  with Machine.create() as parent:
      parent.files.write("/workspace/state.txt", "base\n")
      child = parent.fork()
      try:
          child.files.write("/workspace/state.txt", "child\n")
          print(parent.files.read("/workspace/state.txt").strip())
          print(child.files.read("/workspace/state.txt").strip())
      finally:
          child.kill()
  ```

  ```bash CLI theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  nullspace machine fork mch_123 --json
  ```

  ```bash HTTP API theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
  curl -fsS -X POST \
    -H "Authorization: Bearer ${NULLSPACE_API_KEY}" \
    -H "Idempotency-Key: fork-${USER}-$(date +%s)" \
    "${NULLSPACE_API_URL}/v1/machines/${MACHINE_ID}/fork"
  ```
</CodeGroup>

API reference: [forkMachine](../api-reference) (`POST /v1/machines/{id}/fork`).

Guide: [Machine lifecycle](../guides/machine-lifecycle). Example:
[Examples](../examples).
