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

# LangGraph

> Keep LangGraph checkpoints from SqliteSaver, and the files your agent writes, on an Archil disk, so a thread continues on any machine or sandbox.

[LangGraph](https://docs.langchain.com/oss/python/langgraph/persistence) saves a thread's state with a checkpointer. `SqliteSaver`, from the `langgraph-checkpoint-sqlite` package, writes every checkpoint to one SQLite file. On a sandbox's or container's local disk, that file goes away with the machine. On an Archil disk, it outlives the machine, and the next machine that mounts the disk continues the thread where it stopped, with the files the agent wrote right next to it.

> [!NOTE]
>
> SQLite takes one writing machine per database file. Mount the disk on one machine at a time, as below, or give each
> agent its own disk. If many workers on different machines serve the same threads at once, use LangGraph's
> `PostgresSaver` instead, and keep the files on the disk. See [one writer at a time](#one-writer-at-a-time).

## Mount a disk

Create a disk in the [Archil console](https://console.archil.com) and save a [disk token](https://docs.archil.com/concepts/authorization.md#token-based-disk-authorization) for it. Then mount it on the machine that runs the agent:

> [tab] Any Linux host
>
> Your own server, a container with FUSE access, or another provider's sandbox. See [Mount on Linux](https://docs.archil.com/mounting/linux.md) for the requirements.
>
> ```bash theme={null}
> curl -s https://archil.com/install | sh
> export ARCHIL_MOUNT_TOKEN="<disk-token>"
> sudo mkdir -p /mnt/archil
> sudo --preserve-env=ARCHIL_MOUNT_TOKEN archil mount dsk-0123456789abcdef /mnt/archil --region aws-us-west-2
> ```

> [tab] Archil sandbox
>
> Pass the disk in `mounts` when you create the [sandbox](https://docs.archil.com/compute/sandboxes/introduction.md#attaching-an-archil-disk), and Archil mounts it for you:
>
> ```python theme={null}
> import archil
>
> sandbox = archil.create_sandbox(
>     name="langgraph-agent",
>     base_image="python:3.13",
>     mounts=[archil.SandboxMountSpec(disk="dsk-0123456789abcdef", path="/mnt/archil")],
> )
> ```

## Point the checkpointer at the disk

Install LangGraph and the SQLite checkpointer:

```bash theme={null}
pip install langgraph langgraph-checkpoint-sqlite
```

This graph has one node, `work`, where your model and tool calls go. Here it writes a file to the thread's workspace on the disk, so you can see the files and the checkpoints persist together. The only Archil-specific line is the path passed to `sqlite3.connect`:

```python agent.py theme={null}
import operator
import sqlite3
import sys
from pathlib import Path
from typing import Annotated, TypedDict

from langgraph.checkpoint.sqlite import SqliteSaver
from langgraph.graph import END, START, StateGraph

STATE_DIR = Path("/mnt/archil/langgraph")
STATE_DIR.mkdir(parents=True, exist_ok=True)


class State(TypedDict):
    tasks: Annotated[list[str], operator.add]


def work(state: State, config) -> dict:
    # Your agent's model and tool calls go here. This node writes a file to the
    # thread's workspace, so the files and the checkpoints live side by side.
    thread_id = config["configurable"]["thread_id"]
    workspace = STATE_DIR / "workspaces" / thread_id
    workspace.mkdir(parents=True, exist_ok=True)
    task = state["tasks"][-1]
    (workspace / f"step-{len(state['tasks'])}.md").write_text(f"# {task}\n")
    return {}


builder = StateGraph(State)
builder.add_node("work", work)
builder.add_edge(START, "work")
builder.add_edge("work", END)

conn = sqlite3.connect(STATE_DIR / "checkpoints.db", check_same_thread=False)
graph = builder.compile(checkpointer=SqliteSaver(conn))

thread_id, task = sys.argv[1], sys.argv[2]
config = {"configurable": {"thread_id": thread_id}}
state = graph.invoke({"tasks": [task]}, config)

print("tasks so far:", state["tasks"])
print("checkpoints:", len(list(graph.get_state_history(config))))
print("files:", sorted(p.name for p in (STATE_DIR / "workspaces" / thread_id).iterdir()))
conn.close()
```

Run two turns of the same thread:

```bash theme={null}
python3 agent.py research-42 "find the dataset"
python3 agent.py research-42 "clean the dataset"
```

```text theme={null}
tasks so far: ['find the dataset']
checkpoints: 3
files: ['step-1.md']
tasks so far: ['find the dataset', 'clean the dataset']
checkpoints: 6
files: ['step-1.md', 'step-2.md']
```

## Continue on another machine

Unmount the disk, which flushes every write to Archil, and mount it on a different machine. In an Archil sandbox, stopping or deleting the sandbox does the same; the disk and its data are kept.

```bash theme={null}
# On the first machine
sudo archil unmount /mnt/archil

# On the second machine, after mounting the disk as above
python3 agent.py research-42 "write the report"
```

The new machine picks up the thread's earlier turns from the checkpoints and the files from the workspace:

```text theme={null}
tasks so far: ['find the dataset', 'clean the dataset', 'write the report']
checkpoints: 9
files: ['step-1.md', 'step-2.md', 'step-3.md']
```

## What's on the disk

| Path | Written by | What it holds |
| - | - | - |
| `/mnt/archil/langgraph/checkpoints.db` | `SqliteSaver` | Every checkpoint of every thread, by `thread_id`. `SqliteSaver` switches the database to [WAL mode](https://www.sqlite.org/wal.html), which works because one machine has the disk mounted at a time. |
| `/mnt/archil/langgraph/workspaces/<thread_id>/` | Your nodes and tools | The files the agent works on: downloads, code, reports. Keep large files here and only their paths in the graph state. |

Any LangGraph feature that reads checkpoints, such as `get_state_history`, time travel and human-in-the-loop interrupts, works across machines the same way, because it reads the same file. A [checkpoint or branch](https://docs.archil.com/concepts/branches-and-checkpoints.md) of the disk captures the checkpoints and the workspace together.

## One writer at a time

By default, a mount takes [exclusive access](https://docs.archil.com/concepts/sharing-disks.md) to the disk, so a second machine can't mount it for writing while the first one has it. That's what SQLite needs: its file locks don't extend across machines, and [SQLite's own docs](https://www.sqlite.org/wal.html) say WAL mode needs every process using a database on the same host. A second `archil mount` while the disk is mounted elsewhere stops with:

```text theme={null}
A force mount will revoke any other delegations outstanding from any other clients mounting the disk, which will cause in-progress writes from those clients to fail.
```

To run many agents at once, give each agent, tenant or task [its own disk](https://docs.archil.com/guides/storage/per-tenant-storage.md), each with its own `checkpoints.db`. If many workers on different machines need to write the same threads at the same time, use `PostgresSaver` from `langgraph-checkpoint-postgres` for the checkpoints, keep the files on an Archil disk, and store their paths in the graph state.

## Next steps

> [card] [Agent frameworks](https://docs.archil.com/guides/agents/agent-frameworks.md)
>
> What CrewAI, the OpenAI Agents SDK and Microsoft Agent Framework keep in files.

> [card] [Temporal](https://docs.archil.com/guides/agents/temporal.md)
>
> Durable workflows, with each activity in its own sandbox and its files on a disk.

> [card] [Sharing disks](https://docs.archil.com/concepts/sharing-disks.md)
>
> Exclusive, shared and conditional mounts.

> [card] [Performance tips](https://docs.archil.com/details/performance-tips.md#sqlite)
>
> Getting the most out of SQLite on a disk.


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