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

# Vercel Sandbox

> Mount an Archil disk in a Vercel Sandbox so its files outlive the sandbox.

A [Vercel Sandbox](https://vercel.com/docs/vercel-sandbox) is a short-lived microVM: when it stops or its timeout runs out, 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. Vercel Sandbox VMs support FUSE, so the disk mounts as a regular directory.

## Prerequisites

Export your Archil API key and region, install the Archil and Vercel Sandbox SDKs, and link the directory to a Vercel project with the [Vercel CLI](https://vercel.com/docs/cli). On your machine, `@vercel/sandbox` authenticates as the linked project.

```bash theme={null}
export ARCHIL_API_KEY=key-...
export ARCHIL_REGION=aws-us-east-1
npm init -y && npm pkg set type=module
npm install disk @vercel/sandbox tsx
vercel link
```

## Mount a disk

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

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

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

Run it with `eval "$(npx tsx setup.ts)"` to export the disk ID and the disk's [mount token](/concepts/authorization#token-based-disk-authorization), which grants access to this disk only. In a Vercel Function, store both as [environment variables](https://vercel.com/docs/environment-variables) instead.

Now start a sandbox in the Vercel region next to the disk, install the `archil` client, mount the disk at `/mnt/archil`, and write a file. The commands run as root, and the token is passed only to the mount command:

```typescript mount.ts theme={null}
import { Sandbox } from "@vercel/sandbox";

const { ARCHIL_DISK_ID, ARCHIL_REGION, ARCHIL_MOUNT_TOKEN } = process.env;
const regions: Record<string, string> = { "aws-us-east-1": "iad1", "aws-us-west-2": "pdx1", "aws-eu-west-1": "dub1" };
const sandbox = await Sandbox.create({ region: regions[ARCHIL_REGION!], persistent: false, timeout: 5 * 60_000 });

async function run(script: string, env: Record<string, string> = {}) {
  const result = await sandbox.runCommand({ cmd: "bash", args: ["-c", script], env, sudo: true });
  if (result.exitCode !== 0) throw new Error(await result.stderr());
  return result.stdout();
}

try {
  await run("apt-get update -qq && curl -fsSL https://archil.com/install | sh > /dev/null");
  await run(`mkdir -p /mnt/archil && 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.name}" >> /mnt/archil/hello.txt && cat /mnt/archil/hello.txt`));
  } finally {
    // Flush buffered writes and release the disk before the sandbox stops
    await run("archil unmount /mnt/archil");
  }
} finally {
  await sandbox.stop();
}
```

The `archil` client buffers recent writes, so the script unmounts before it stops the sandbox: `archil unmount` returns once every write has reached the disk. Run `npx tsx mount.ts` twice. Each run starts a new sandbox, and the second one finds the line the first one wrote:

```text theme={null}
Hello from sapphire-vocational-porpoise-kBFwUh

Hello from sapphire-vocational-porpoise-kBFwUh
Hello from coffee-causal-porcupine-4NZYwH
```

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:

```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")));
```

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

## Clean up

Delete the disk with the [`disk` CLI](/reference/disk-cli). The sandboxes already stopped at the end of each run.

```bash theme={null}
npx disk delete "$ARCHIL_DISK_ID"
```

## Next steps

* [TypeScript SDK](/sdks/typescript): 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.