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

# Modal

> Mount an Archil disk in Modal Sandboxes so their files outlive the container.

[Modal](https://modal.com) containers start fast, but their files disappear when they exit. Mount an Archil disk in a Modal Sandbox and anything written there stays on the disk, where the next Sandbox can mount it and your app can read it with the Archil SDK, without starting any compute.

`archil mount` uses FUSE, which Modal supports in [VM Sandboxes](https://modal.com/docs/guide/vm-sandboxes) (`runtime="vm"`). Modal Functions and Sandboxes on the default runtime can't mount FUSE file systems. From those, read and write the disk with the [Python SDK](/sdks/python) (`get_object` and `put_object`, with `ARCHIL_API_KEY` and `ARCHIL_REGION` in a Modal Secret), the same way the last step below reads it from your machine.

## Prerequisites

Export your Archil API key and region, then install the Archil and Modal SDKs and sign in to Modal:

```bash theme={null}
export ARCHIL_API_KEY=key-...
export ARCHIL_REGION=aws-us-east-1
pip install archil modal
modal setup
```

## Mount a disk

First, create a disk and store its [mount token](/concepts/authorization#token-based-disk-authorization) in a [Modal Secret](https://modal.com/docs/guide/secrets). The token grants access to this disk only. You only do this once:

```python setup.py theme={null}
import archil
import modal

result = archil.create_disk(name="modal-data")
modal.Secret.objects.create("archil-mount", {"ARCHIL_MOUNT_TOKEN": result.token})
print(f"export ARCHIL_DISK_ID={result.disk.id}")
```

Run it with `eval "$(python setup.py)"` to export the disk ID.

Now start a VM Sandbox from an image with the `archil` client installed. The Sandbox mounts the disk at `/mnt/archil`, writes a file, and unmounts on exit:

```python sandbox.py theme={null}
import os

import modal

app = modal.App("archil-mount")
image = modal.Image.debian_slim().apt_install("curl").run_commands("curl -fsSL https://archil.com/install | sh")

SCRIPT = """
set -e
mkdir -p /mnt/archil
archil mount "$ARCHIL_DISK_ID" /mnt/archil --region "$ARCHIL_REGION" > /dev/null
trap 'archil unmount /mnt/archil > /dev/null' EXIT
echo "Hello from $MODAL_TASK_ID" >> /mnt/archil/hello.txt
cat /mnt/archil/hello.txt
"""


@app.local_entrypoint()
def main():
    sandbox = modal.Sandbox.create(
        "bash", "-c", SCRIPT,
        app=app,
        image=image,
        runtime="vm",
        secrets=[modal.Secret.from_name("archil-mount")],
        env={"ARCHIL_DISK_ID": os.environ["ARCHIL_DISK_ID"], "ARCHIL_REGION": os.environ["ARCHIL_REGION"]},
        timeout=5 * 60,
    )
    sandbox.wait()
    if sandbox.returncode != 0:
        raise RuntimeError(sandbox.stderr.read())
    print(sandbox.stdout.read())
```

The `archil` client buffers recent writes, so the `trap` unmounts before the Sandbox exits, even if a command fails: `archil unmount` returns once every write has reached the disk. Run `modal run sandbox.py` twice. Each run starts a new Sandbox, and the second one finds the line the first one wrote:

```text theme={null}
Hello from ta-01M55BF71CCMH321JDE0XTP6TV

Hello from ta-01M55BF71CCMH321JDE0XTP6TV
Hello from ta-01M55BFBF4D404NCTHT4ZCEYHV
```

A plain mount is exclusive: one Sandbox holds the disk at a time. To mount it in several Sandboxes at once, add `--shared`, and see [Sharing disks](/concepts/sharing-disks).

## Read it from anywhere

Both Sandboxes are gone, and the file is still on the disk. Read it from your own machine or app with the SDK:

```python read.py theme={null}
import os

import archil

disk = archil.get_disk(os.environ["ARCHIL_DISK_ID"])
print(disk.get_object("hello.txt").decode())
```

If a Sandbox is terminated before it unmounts, see [Troubleshooting mounts on other platforms](/guides/platforms/troubleshooting).

## Clean up

Delete the disk and the Modal Secret with `python cleanup.py`. Apps started with `modal run` stop on their own.

```python cleanup.py theme={null}
import os

import archil
import modal

archil.get_disk(os.environ["ARCHIL_DISK_ID"]).delete()
modal.Secret.objects.delete("archil-mount")
```

## Next steps

* [Python SDK](/sdks/python): read, write, and search the disk without mounting it.
* [Persistent sandboxes](/compute/sandboxes/introduction): Archil's own sandboxes, with the disk mounted for you.


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