> ## Documentation Index
> Fetch the complete documentation index at: https://blaxel-mendral-deps-weekly-safe-github-actions-20260803.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Snapshots and forking

> Create point-in-time snapshots of sandboxes, roll them back to previous checkpoint, and fork them into new sandboxes.

<Note>
  This feature is currently in private preview and is not recommended for production use.
</Note>

Snapshots capture the current state of a sandbox at a point in time. Use snapshots to checkpoint sandbox state to allow rollbacks after making changes, or as the basis for forking a sandbox into a new sandbox.

## Create a snapshot

Create a snapshot of an existing sandbox. The snapshot captures the filesystem, running processes, and memory state.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { SandboxInstance } from "@blaxel/core";

  const sandbox = await SandboxInstance.get("my-sandbox");
  const snapshot = await sandbox.snapshot("before-migration");
  ```

  ```python Python theme={null}
  from blaxel.core import SandboxInstance

  sandbox = await SandboxInstance.get("my-sandbox")
  snapshot = await sandbox.snapshot("before-migration")
  ```

  ```bash HTTP API theme={null}
  curl -X POST https://api.blaxel.ai/v0/sandboxes/my-sandbox/snapshots \
    -H "Authorization: Bearer $BL_API_KEY" \
    -H "X-Blaxel-Workspace: my-workspace" \
    -H "Content-Type: application/json" \
    -d '{ "name": "before-migration" }'
  ```
</CodeGroup>

## List snapshots

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { SandboxInstance } from "@blaxel/core";

  const sandbox = await SandboxInstance.get("my-sandbox");
  const snapshots = await sandbox.listSnapshots();
  ```

  ```python Python theme={null}
  from blaxel.core import SandboxInstance

  sandbox = await SandboxInstance.get("my-sandbox")
  snapshots = await sandbox.list_snapshots()
  ```

  ```bash HTTP API theme={null}
  curl https://api.blaxel.ai/v0/sandboxes/my-sandbox/snapshots \
    -H "Authorization: Bearer $BL_API_KEY" \
    -H "X-Blaxel-Workspace: my-workspace"
  ```
</CodeGroup>

## Delete a snapshot

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { SandboxInstance } from "@blaxel/core";

  const sandbox = await SandboxInstance.get("my-sandbox");
  await sandbox.deleteSnapshot("snap_abc123");
  ```

  ```python Python theme={null}
  from blaxel.core import SandboxInstance

  sandbox = await SandboxInstance.get("my-sandbox")
  await sandbox.delete_snapshot("snap_abc123")
  ```

  ```bash HTTP API theme={null}
  curl -X DELETE https://api.blaxel.ai/v0/sandboxes/my-sandbox/snapshots/snap_abc123 \
    -H "Authorization: Bearer $BL_API_KEY" \
    -H "X-Blaxel-Workspace: my-workspace"
  ```
</CodeGroup>

## Fork a sandbox

Forking creates a new sandbox from an existing one, forking its entire memory state (files + running processes). The fork inherits the source sandbox's image, memory configuration, environment variables, and port settings.

Calling `fork()` automatically snapshots the source sandbox's current state and forks from it — you don't need to create a snapshot first.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { SandboxInstance } from "@blaxel/core";

  const sandbox = await SandboxInstance.get("my-sandbox");
  const result = await sandbox.fork("my-sandbox-copy");
  ```

  ```python Python theme={null}
  from blaxel.core import SandboxInstance

  sandbox = await SandboxInstance.get("my-sandbox")
  result = await sandbox.fork("my-sandbox-copy")
  ```

  ```bash CLI theme={null}
  bl fork sbx/my-sandbox sbx/my-sandbox-copy
  ```

  ```bash HTTP API theme={null}
  curl -X POST https://api.blaxel.ai/v0/sandboxes/my-sandbox/fork \
    -H "Authorization: Bearer $BL_API_KEY" \
    -H "X-Blaxel-Workspace: my-workspace" \
    -H "Content-Type: application/json" \
    -d '{
      "targetType": "sandbox",
      "targetName": "my-sandbox-copy"
    }'
  ```
</CodeGroup>

### Fork from a snapshot

To create a sandbox from a snapshot you took earlier, pass its `snapshotId`. The fork is created from that snapshot instead of the source sandbox's current state:

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { SandboxInstance } from "@blaxel/core";

  const sandbox = await SandboxInstance.get("my-sandbox");
  const result = await sandbox.fork("my-sandbox-copy", {
    targetType: "sandbox",
    snapshotId: "snap_abc123",
  });
  ```

  ```python Python theme={null}
  from blaxel.core import SandboxInstance

  sandbox = await SandboxInstance.get("my-sandbox")
  result = await sandbox.fork(
      "my-sandbox-copy",
      target_type="sandbox",
      snapshot_id="snap_abc123",
  )
  ```

  ```bash HTTP API theme={null}
  curl -X POST https://api.blaxel.ai/v0/sandboxes/my-sandbox/fork \
    -H "Authorization: Bearer $BL_API_KEY" \
    -H "X-Blaxel-Workspace: my-workspace" \
    -H "Content-Type: application/json" \
    -d '{
      "targetType": "sandbox",
      "targetName": "my-sandbox-copy",
      "snapshotId": "snap_abc123"
    }'
  ```
</CodeGroup>

## Fork request parameters

| Parameter    | Type    | Description                                            |
| ------------ | ------- | ------------------------------------------------------ |
| `targetType` | string  | Target resource type: `sandbox`                        |
| `targetName` | string  | Name of the sandbox to create                          |
| `port`       | integer | Port to expose                                         |
| `snapshotId` | string  | Fork from a specific snapshot instead of current state |

<CardGroup cols={1}>
  <Card title="Sandbox overview" icon="cube" href="/Sandboxes/Overview">
    Learn more about sandbox lifecycle and configuration.
  </Card>
</CardGroup>
