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

> ## Agent Instructions
> Install the Beam CLI, sign in, and connect coding agents to the Beam MCP server with `curl -fsSL https://www.beam.cloud/install | sh`. To also create a VM, run `curl -fsSL https://www.beam.cloud/install | sh -s -- --vm`.
> VMs are persistent Linux machines without GPUs. Defaults: 4 CPUs, 8 GiB of RAM, a 50 GiB disk, Ubuntu 24.04, and a browser desktop. A running VM accrues usage until you stop, pause, or remove it, or until an idle timeout puts it to sleep.
> Stopping a VM keeps its disk and discards RAM and processes. Pausing keeps both, and resuming restores them. To pause after 5 idle minutes and wake on access, run `beam vm update NAME --ttl 300 --idle-action pause --auto-resume`.
> Core VM commands: `beam vm new NAME`, `beam vm ssh NAME`, `beam vm sync NAME ./dir`, `beam vm exec NAME -- CMD`, `beam vm expose NAME PORT --protected`, `beam vm fork NAME NEW_NAME`, `beam vm pause NAME`, `beam vm stop NAME`, `beam vm rm NAME`.
> For GPUs, use a sandbox or a deployed endpoint. Sandboxes are disposable environments that boot in seconds and fork from snapshots.
> Current rates are at https://www.beam.cloud/pricing.

# Snapshots

Snapshots let you capture the filesystem and/or memory of a Sandbox as an immutable artifact.
You can then use this artifact to create new Sandboxes with that same captured state.

Use snapshots when you want to:

* Fork Sandboxes to test different variations of code
* Initialize Sandboxes with existing state for faster cold starts
* Save a reproducible environment you can return to later

A filesystem image and a memory checkpoint are different artifacts. `create_image_from_filesystem()` returns an **image ID** for `Image.from_id`; `snapshot_memory()` returns a **checkpoint ID** for `create_from_memory_snapshot`. They are not interchangeable.

Wait for writes and initialization to finish before capturing state. Mounted volumes and durable disks have their own persistence behavior; a reusable root-filesystem image is not a backup of every mounted dataset. See [durable disks](https://docs.beam.cloud/v2/data/durable-disks.md#snapshots).

> [!NOTE]
>
> Storage is not billed yet. Planned pricing is **\$0.0001 per GB-hour of data stored**, with no free allowance.
>
> This will use the same usage credits as compute and cover retained VM disk, volume, and snapshot data, including while compute is stopped. Empty disk capacity, shared base images, and internal copies are excluded. 1 GB = 1 billion bytes.

## Creating a Filesystem Snapshot

```python theme={null}
from beam import Image, Sandbox

# Create a sandbox and make some changes to the filesystem
sandbox = Sandbox(cpu=1).create()
p = sandbox.process.exec("sh", "-c", "mkdir -p /something && touch /something/file.txt")

# Read the logs
p.wait()
print(p.logs.read())

# Generate a filesystem snapshot and terminate the sandbox
image_id = sandbox.create_image_from_filesystem()
sandbox.terminate()
```

## Using Filesystem Snapshots

You can use Snapshots as a base image for any other abstraction or Sandbox on Beam, using `Image.from_id`:

```python theme={null}
from beam import Image, Sandbox

# Creates an image from a filesystem snapshot
image = Image.from_id(image_id)

sandbox = Sandbox(image=image).create()
p = sandbox.process.exec("ls", "-l", "/something")

p.wait()
print(p.logs.read())

sandbox.terminate()
```

## Creating a Memory Snapshot

You can also create a memory snapshot of a running Sandbox, which captures the sandbox's process state and filesystem on supported runtimes. Restored sandboxes receive their own identity and URLs; inspect `list_urls()` on the restored instance.

```python theme={null}
from beam import Image, Sandbox

# Create a sandbox and make some changes to the filesystem
sandbox = Sandbox(cpu=1).create()
sandbox.expose_port(8000)

p = sandbox.process.exec("python", "-c", "import http.server; http.server.HTTPServer(('', 8000), http.server.SimpleHTTPRequestHandler).serve_forever()")

# Wait until the server is accepting connections before capturing it.
ready = sandbox.process.run_code("""
import socket
import time
for _ in range(100):
    try:
        with socket.create_connection(("127.0.0.1", 8000), timeout=1):
            break
    except OSError:
        time.sleep(0.1)
else:
    raise RuntimeError("server not ready")
""")
if ready.exit_code != 0:
    sandbox.terminate()
    raise RuntimeError("server did not become ready; snapshot cancelled")

# Generate a memory snapshot and terminate the sandbox
snapshot_id = sandbox.snapshot_memory()

print(sandbox.list_urls())

sandbox.terminate()
```

## Using Memory Snapshots

You can use memory snapshots as a starting point for a new Sandbox, using `Sandbox().create_from_memory_snapshot`:

```python theme={null}
from beam import Image, Sandbox

# Creates a new sandbox from a memory snapshot

sandbox = Sandbox().create_from_memory_snapshot(snapshot_id)

print(sandbox.list_urls())

sandbox.terminate()
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.