Skip to main content
Fork clones a running sandbox — memory, processes, and filesystem — into an independent child. This example writes shared state, forks, then changes each side to show they no longer affect each other.

Setup

uv pip install "nullspace-sdk==0.1.9"
export NULLSPACE_API_KEY=ns_live_...
export NULLSPACE_API_URL=https://api.your-nullspace-domain

Python

fork_example.py
from nullspace import Sandbox

with Sandbox.create(template="base", timeout=120) as parent:
    parent.files.write("/workspace/state.txt", "common\n")

    child = parent.fork()
    try:
        parent.files.write("/workspace/state.txt", "common\nparent\n")
        child.files.write("/workspace/state.txt", "common\nchild\n")

        print("parent:", parent.files.read("/workspace/state.txt").split())
        print("child: ", child.files.read("/workspace/state.txt").split())
    finally:
        child.kill()

Expected output

parent: ['common', 'parent']
child:  ['common', 'child']
The child starts as an exact copy (it sees common), then each side’s write lands only in its own filesystem. Fork children are full sandboxes: fork them again, hibernate them, or expose ports — anything a created sandbox can do.

Where this is useful

  • Parallel exploration — set up a repo or environment once, fork per hypothesis, keep the winner.
  • Cheap retries — fork before a risky step; on failure, kill the child and fork again instead of rebuilding state.
  • Evaluation — run N candidate patches against identical warm state.
Related: Fork concept · Sandbox fork guide