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

# Daytona

> Mount an Archil disk in Daytona sandboxes so their files outlive the sandbox.

When you delete a [Daytona](https://daytona.io) sandbox, its files go with it. Mount an Archil disk in the 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 a sandbox. Daytona sandboxes support FUSE, so the disk mounts as a regular directory.

## Prerequisites

Export your Archil API key and region, and your [Daytona API key](https://app.daytona.io/dashboard/keys), then install both SDKs:

<CodeGroup>
  ```bash TypeScript theme={null}
  export ARCHIL_API_KEY=key-...
  export ARCHIL_REGION=aws-us-east-1
  export DAYTONA_API_KEY=dtn_...
  npm init -y && npm pkg set type=module
  npm install disk @daytona/sdk tsx
  ```

  ```bash Python theme={null}
  export ARCHIL_API_KEY=key-...
  export ARCHIL_REGION=aws-us-east-1
  export DAYTONA_API_KEY=dtn_...
  pip install archil daytona
  ```
</CodeGroup>

## Mount a disk

First, create a disk. You only do this once:

<CodeGroup>
  ```typescript setup.ts theme={null}
  import * as archil from "disk";

  const { disk, token } = await archil.createDisk({ name: "daytona-data" });
  console.log(`export ARCHIL_DISK_ID=${disk.id} ARCHIL_MOUNT_TOKEN=${token}`);
  ```

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

  result = archil.create_disk(name="daytona-data")
  print(f"export ARCHIL_DISK_ID={result.disk.id} ARCHIL_MOUNT_TOKEN={result.token}")
  ```
</CodeGroup>

Run it with `eval "$(npx tsx setup.ts)"` (or `eval "$(python setup.py)"`) to export the disk ID and the disk's [mount token](/concepts/authorization#token-based-disk-authorization), which grants access to this disk only.

Now start a sandbox, install the `archil` client, mount the disk at `/mnt/archil` with `sudo`, and write a file. The token is passed only to the mount command:

<CodeGroup>
  ```typescript mount.ts theme={null}
  import { Daytona } from "@daytona/sdk";

  const { ARCHIL_DISK_ID, ARCHIL_REGION, ARCHIL_MOUNT_TOKEN } = process.env;
  const sandbox = await new Daytona().create();

  async function run(command: string, env?: Record<string, string>) {
    const { exitCode, result } = await sandbox.process.executeCommand(command, undefined, env);
    if (exitCode !== 0) throw new Error(result);
    return result;
  }

  try {
    await run("sudo apt-get update -qq && curl -fsSL https://archil.com/install | sh > /dev/null");
    await run(
      `sudo mkdir -p /mnt/archil && sudo --preserve-env=ARCHIL_MOUNT_TOKEN archil mount ${ARCHIL_DISK_ID} /mnt/archil --region ${ARCHIL_REGION}`,
      { ARCHIL_MOUNT_TOKEN: ARCHIL_MOUNT_TOKEN! },
    );
    try {
      console.log(await run(`echo "Hello from ${sandbox.id}" | sudo tee -a /mnt/archil/hello.txt > /dev/null && cat /mnt/archil/hello.txt`));
    } finally {
      // Flush buffered writes and release the disk before the sandbox is deleted
      await run("sudo archil sync /mnt/archil && sudo archil checkin /mnt/archil");
    }
  } finally {
    await sandbox.delete();
  }
  ```

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

  from daytona import Daytona

  sandbox = Daytona().create()


  def run(command, env=None):
      response = sandbox.process.exec(command, env=env)
      if response.exit_code != 0:
          raise RuntimeError(response.result)
      return response.result


  try:
      run("sudo apt-get update -qq && curl -fsSL https://archil.com/install | sh > /dev/null")
      run(
          f"sudo mkdir -p /mnt/archil && sudo --preserve-env=ARCHIL_MOUNT_TOKEN archil mount {os.environ['ARCHIL_DISK_ID']} /mnt/archil --region {os.environ['ARCHIL_REGION']}",
          env={"ARCHIL_MOUNT_TOKEN": os.environ["ARCHIL_MOUNT_TOKEN"]},
      )
      try:
          print(run(f'echo "Hello from {sandbox.id}" | sudo tee -a /mnt/archil/hello.txt > /dev/null && cat /mnt/archil/hello.txt'))
      finally:
          # Flush buffered writes and release the disk before the sandbox is deleted
          run("sudo archil sync /mnt/archil && sudo archil checkin /mnt/archil")
  finally:
      sandbox.delete()
  ```
</CodeGroup>

The `archil` client buffers recent writes, so before the script deletes the sandbox, `archil sync` sends every buffered write to the disk and `archil checkin` releases the sandbox's lock on it. Those are the two steps `archil unmount` takes on other machines, but Daytona doesn't let the client detach the mount.

Run `npx tsx mount.ts` (or `python mount.py`) twice. Each run starts a new sandbox, and the second one finds the line the first one wrote:

```text theme={null}
Hello from 4fa2e3c5-2478-48e3-8a90-ff388946f767

Hello from 4fa2e3c5-2478-48e3-8a90-ff388946f767
Hello from 3f962e2a-1ee7-46e4-a683-5f3892d6643a
```

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

To skip the install in every sandbox, run the same install command in a [Daytona snapshot](https://www.daytona.io/docs/en/snapshots) and create your sandboxes from it.

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

<CodeGroup>
  ```typescript read.ts theme={null}
  import * as archil from "disk";

  const disk = await archil.getDisk(process.env.ARCHIL_DISK_ID!);
  console.log(new TextDecoder().decode(await disk.getObject("hello.txt")));
  ```

  ```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())
  ```
</CodeGroup>

If a sandbox is deleted or stopped before it releases the disk, see [Troubleshooting mounts on other platforms](/guides/platforms/troubleshooting).

## Clean up

Delete the disk. The script already deleted each sandbox.

<CodeGroup>
  ```bash TypeScript theme={null}
  npx disk delete "$ARCHIL_DISK_ID"
  ```

  ```bash Python theme={null}
  python -c 'import os, archil; archil.get_disk(os.environ["ARCHIL_DISK_ID"]).delete()'
  ```
</CodeGroup>

## Next steps

* [`archil` CLI](/reference/archil-cli): every mount option, plus `sync` and `checkin`.
* [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.