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

# Blaxel

> Mount one Archil disk in many Blaxel sandboxes so they share files with each other and with the rest of your stack.

A [Blaxel sandbox](https://docs.blaxel.ai/Sandboxes/Overview) is a microVM that drops to standby when it's idle and resumes on the next request. Its files belong to that one sandbox and go away when you delete it. Mount an Archil disk in your sandboxes and they can all read and write the same files, which outlive any one sandbox and which your other machines and the Archil SDK can reach too.

Blaxel sandboxes run as root and support FUSE, so the disk mounts as a regular directory.

## Prerequisites

* A Blaxel workspace and an API key. Export both so the Blaxel SDK can find them:

  ```bash theme={null}
  export BL_WORKSPACE=my-workspace
  export BL_API_KEY=bl_...
  ```

* An Archil disk in the [Archil region](https://docs.archil.com/reference/regions.md) of your choice, and the Blaxel region nearest to it, such as `us-pdx-1` for `aws-us-west-2`.

Set your Archil API key and both regions, and install the SDKs:

```bash theme={null}
export ARCHIL_API_KEY=key-...
export ARCHIL_REGION=aws-us-west-2
export BL_REGION=us-pdx-1
npm init -y && npm pkg set type=module
npm install disk @blaxel/core tsx
```

Create the disk with the [`disk` CLI](https://docs.archil.com/reference/disk-cli). The output includes the disk ID and a one-time [mount token](https://docs.archil.com/concepts/authorization.md#token-based-disk-authorization), which grants access to this disk only:

```bash theme={null}
npx disk create blaxel-data
```

Export both for the steps below:

```bash theme={null}
export ARCHIL_DISK_ID=dsk-...
export ARCHIL_MOUNT_TOKEN=adt_...
```

## Mount the disk in a sandbox

This script creates a sandbox with the name you pass it, installs the `archil` client, mounts the disk at `/mnt/archil`, and writes a file to it. The token is passed only to the mount command:

```typescript mount.ts theme={null}
import { SandboxInstance } from "@blaxel/core";

const { ARCHIL_DISK_ID, ARCHIL_REGION, ARCHIL_MOUNT_TOKEN, BL_REGION } = process.env;
const name = process.argv[2];
const sandbox = await SandboxInstance.createIfNotExists({ name, region: BL_REGION });

async function run(command: string, env: Record<string, string> = {}) {
  const result = await sandbox.process.exec({ command, env, waitForCompletion: true, timeout: 120 });
  if (result.exitCode !== 0) throw new Error(result.stderr || result.stdout);
  return result.stdout;
}

await run("apk add --no-cache curl && curl -fsSL https://archil.com/install | sh");
await run(`mkdir -p /mnt/archil && archil mount ${ARCHIL_DISK_ID} /mnt/archil --region ${ARCHIL_REGION} --conditional`, {
  ARCHIL_MOUNT_TOKEN: ARCHIL_MOUNT_TOKEN!,
});
console.log(await run(`echo "Hello from ${name}" >> /mnt/archil/visits.log && cat /mnt/archil/visits.log`));
```

Run it to create the first sandbox:

```bash theme={null}
npx tsx mount.ts archil-one
```

```text theme={null}
Hello from archil-one
```

## Share the disk between sandboxes

Run the script again with a new name:

```bash theme={null}
npx tsx mount.ts archil-two
```

Both sandboxes have the disk mounted at the same time, and the second one finds the line the first one wrote:

```text theme={null}
Hello from archil-one
Hello from archil-two
```

## How the disk behaves in a sandbox

**The mount uses conditional mode.** With `--conditional`, every sandbox can read and write anywhere on the disk at the same time, and none of them holds a lock that another sandbox has to wait for. See [Sharing disks](https://docs.archil.com/concepts/sharing-disks.md).

**Standby needs no special handling.** When a sandbox goes to standby, the mount is suspended with it, and the client reconnects when the sandbox resumes.

**Unmount before you delete a sandbox.** The `archil` client buffers recent writes, and `archil unmount` returns once every one of them has reached the disk. Deleting a sandbox without unmounting can lose writes from its last few seconds.

## Clean up

This script unmounts the disk in each sandbox you name, then deletes the sandbox:

```typescript cleanup.ts theme={null}
import { SandboxInstance } from "@blaxel/core";

for (const name of process.argv.slice(2)) {
  const sandbox = await SandboxInstance.get(name);
  await sandbox.process.exec({ command: "archil unmount /mnt/archil", waitForCompletion: true, timeout: 60 });
  await SandboxInstance.delete(name);
}
```

Run it on both sandboxes, then delete the disk once you no longer need it:

```bash theme={null}
npx tsx cleanup.ts archil-one archil-two
npx disk delete "$ARCHIL_DISK_ID"
```

## Next steps

* [TypeScript SDK](https://docs.archil.com/sdks/typescript.md): read, write, and search the disk without mounting it.
* [Sharing disks](https://docs.archil.com/concepts/sharing-disks.md): how conditional mode and checkouts work.
* [`archil` CLI reference](https://docs.archil.com/reference/archil-cli): every `archil mount` option.


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