> ## 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.

# CrewAI

> Keep CrewAI flow state and memory on an Archil disk with CREWAI_STORAGE_DIR, so a flow resumes on any machine or sandbox.

[CrewAI](https://docs.crewai.com) keeps its state in local files. Flows decorated with [`@persist`](https://docs.crewai.com/en/concepts/flows) save their state to a SQLite database, `flow_states.db`, and crew [memory](https://docs.crewai.com/en/concepts/memory) is stored with LanceDB in a `memory` directory. Both go under one storage directory, which you choose with the `CREWAI_STORAGE_DIR` environment variable. Point it at an Archil disk, and a flow started in one sandbox resumes in another with its state intact.

> [!NOTE]
>
> Run one machine against the storage directory at a time: `flow_states.db` is a SQLite file, and CrewAI's docs say
> a fixed knowledge folder allows one process at a time. To run many crews at once, give each its own disk. If many
> machines must write the same flow state concurrently, write a custom `FlowPersistence` backed by a database such as
> Postgres.

## 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 crew:

> [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 set `CREWAI_STORAGE_DIR` for every command in it:
>
> ```python theme={null}
> import archil
>
> sandbox = archil.create_sandbox(
>     name="crewai-flow",
>     base_image="python:3.13",
>     mounts=[archil.SandboxMountSpec(disk="dsk-0123456789abcdef", path="/mnt/archil")],
>     env={"CREWAI_STORAGE_DIR": "/mnt/archil/crewai"},
> )
> ```

## Point CrewAI's storage at the disk

Install CrewAI and set the storage directory to a path on the disk:

```bash theme={null}
pip install crewai
export CREWAI_STORAGE_DIR=/mnt/archil/crewai
```

This flow has one step, where your crew or LLM calls go. `@persist()` saves the flow's state after each method, and passing an `id` in the inputs resumes the flow with that ID:

```python flow.py theme={null}
import sys

from crewai.flow.flow import Flow, start
from crewai.flow.persistence import persist
from pydantic import BaseModel


class ResearchState(BaseModel):
    topic: str = ""
    notes: list[str] = []


@persist()
class ResearchFlow(Flow[ResearchState]):
    @start()
    def take_note(self):
        # Your crew or LLM calls go here; the flow's state is saved after each method.
        self.state.notes.append(f"note {len(self.state.notes) + 1} on {self.state.topic}")


flow = ResearchFlow()
inputs = {"topic": sys.argv[1]}
if len(sys.argv) > 2:
    inputs["id"] = sys.argv[2]  # resume the flow with this ID
flow.kickoff(inputs=inputs)

print("flow id:", flow.state.id)
print("notes:", flow.state.notes)
```

Start a flow. CrewAI prints its progress panels, then the script's lines:

```bash theme={null}
python3 flow.py "vector databases"
```

```text theme={null}
flow id: 05c4317f-e5f6-4c3c-a059-a0f23f22f516
notes: ['note 1 on vector databases']
```

The storage directory now holds the flow database, next to the directory memory uses:

```text theme={null}
/mnt/archil/crewai/.crewai_user.json
/mnt/archil/crewai/flow_states.db
/mnt/archil/crewai/memory
```

## Resume 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. Then resume the flow by its ID:

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

# On the second machine, after mounting the disk and setting CREWAI_STORAGE_DIR as above
python3 flow.py "vector databases" 05c4317f-e5f6-4c3c-a059-a0f23f22f516
```

```text theme={null}
flow id: 05c4317f-e5f6-4c3c-a059-a0f23f22f516
notes: ['note 1 on vector databases', 'note 2 on vector databases']
```

## What's on the disk

| Data | Where it goes | Notes |
| - | - | - |
| Flow state from `@persist` | `$CREWAI_STORAGE_DIR/flow_states.db` | A SQLite file, with one writing machine at a time. To fork a flow from a saved state instead of resuming it, pass `restore_from_state_id` to `kickoff`. |
| Crew memory | `$CREWAI_STORAGE_DIR/memory` | LanceDB files. Memory also calls an LLM and an embedder, OpenAI's by default, when it saves and recalls; see [CrewAI's memory docs](https://docs.crewai.com/en/concepts/memory). |
| Knowledge | A temporary folder per process, by default | To keep knowledge between runs, set a fixed Qdrant path on the disk with `set_rag_config(QdrantConfig(options={"path": "/mnt/archil/crewai/knowledge"}))`. CrewAI's [knowledge docs](https://docs.crewai.com/en/concepts/knowledge) say a fixed folder allows one process at a time. |
| Files your tools write | Wherever your tools write | Point file tools and output paths at the disk, such as `/mnt/archil/crewai/work`, so the crew's files persist with its state. |

## 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 matches what CrewAI's local storage expects: SQLite's file locks don't extend across machines, and a fixed knowledge folder serves one process. A second `archil mount` while the disk is mounted elsewhere stops with a message about revoking the other client's delegations.

To run many crews at once, give each crew, tenant or task [its own disk](https://docs.archil.com/guides/storage/per-tenant-storage.md) and its own `CREWAI_STORAGE_DIR`. If many machines must write the same flows concurrently, implement CrewAI's `FlowPersistence` interface on a database such as Postgres, and keep the crew's files on the disk.

## Next steps

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

> [card] [LangGraph](https://docs.archil.com/guides/agents/langgraph.md)
>
> LangGraph checkpoints in a SQLite file on a disk.

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

> [card] [Per-tenant storage](https://docs.archil.com/guides/storage/per-tenant-storage.md)
>
> One disk per tenant, provisioned through the API.


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