Skip to content
AnswerWell geo Documentation

Research · 9 min read · Answerwell

Sandbox Bucket Mount: FUSE, Credentials, and Lifecycle Persistence

How Cloudflare Sandbox mounts S3-compatible buckets as paths, keeps data across sandbox lifecycles, and configures credentials and FUSE in containers.

This page summarises Cloudflare Sandbox documentation on mounting S3-compatible object storage—especially Cloudflare R2—as local filesystem paths inside sandboxes and related container runtimes. The goal is persistent data access with ordinary file operations (open, cat, cp) instead of bespoke download/upload logic.

mountBucket and S3Mount: what bucket mounting does

Section titled “mountBucket and S3Mount: what bucket mounting does”

Bucket mounting exposes object storage as a directory inside the sandbox (or container) filesystem. The Storage API states that you can:

Mount S3-compatible storage buckets (R2, S3, GCS) into the sandbox filesystem for persistent data access.

The Sandbox SDK API overview describes the same idea at a high level: mount buckets as local filesystems for persistent data storage across sandbox lifecycles.

In Sandbox SDK 0.x, the primary API is mountBucket() on a sandbox instance (see mount buckets guide and Storage API). In @cloudflare/sandbox 1.0, new work should use S3Mount with S3Gateway exported from the Worker; credentials stay in the Worker and the container never receives real keys (Mount an R2 bucket, S3Mount API).

Two related paths appear in the cluster:

Approach Where it runs How storage is accessed
mountBucket() / S3Mount Cloudflare Sandbox (Durable Object + container) SDK uses s3fs-fuse under the hood; 1.0 signs requests via S3Gateway
FUSE in Cloudflare Containers Your container image You install adapters such as tigrisfs, s3fs, or gcsfuse and mount at startup

Cloudflare Containers now support mounting R2 buckets as FUSE volumes:

Containers now support mounting R2 buckets as FUSE (Filesystem in Userspace) volumes, allowing applications to interact with R2 using standard filesystem operations.

That path is for images you control; the Sandbox SDK path integrates mounting with sandbox lifecycle and (in 1.0) outbound interception. The Mount R2 buckets with FUSE example notes a practical limit:

FUSE provides filesystem access to object storage. It does not provide local-disk performance or full POSIX filesystem semantics.

When to mount a bucket instead of a snapshot

Section titled “When to mount a bucket instead of a snapshot”

People usually mount buckets when data must survive sandbox destruction, stay cheap compared with keeping sandboxes alive, or be shared across sandboxes or Workers.

The mount buckets guide lists typical reasons:

  • Persistent data — data survives sandbox destruction
  • Large datasets — process data without downloading everything up front
  • Shared storage — multiple sandboxes read the same objects
  • Cost-effective persistence — cheaper than keeping sandboxes alive

Sandbox lifetime sharpens the split between snapshots and mounts:

Files in a mounted R2 bucket are objects in that bucket. They remain after every instance stops, and other sandboxes and Workers with access to the bucket can read them. A snapshot does not include mounted directories, and a mount ends with its instance, so each new instance mounts the bucket again.

Use a snapshot for files that belong to one continuing workspace. Use a bucket for files that other systems read, or that must outlive the workspace.

Work with files adds that you can combine both: keep a repo in a snapshot and write results to a mounted bucket for other Workers.

Mounting at /workspace or under it can surprise you in production. The mount buckets guide explains that in production the mount overlays that path rather than merging with files already in the image. For a persistent project tree, Backup and restore (linked from the same docs) is often a better fit than mounting /workspace.

mountBucket(): R2 binding, remote endpoint, and local dev

Section titled “mountBucket(): R2 binding, remote endpoint, and local dev”

In SDK 0.x, mountBucket(bucket, mountPath, options?) supports three modes (Storage API):

  1. R2 binding mount — omit endpoint; the first argument is the Worker R2 binding name (for example MY_BUCKET), not necessarily the dashboard bucket name.
  2. Local R2 binding mount — set localBucket: true under wrangler dev for sync-style access to the binding.
  3. Remote endpoint mount — set endpoint and pass the remote bucket name; credentials are explicit or auto-detected from Worker secrets.

The HTTP bridge documents the same split for non-SDK clients (HTTP API):

When options.endpoint is omitted, bucket means the Worker R2 binding name.

When endpoint is provided, bucket means the remote bucket name. Credentials are optional in this mode only — the bridge auto-detects from Worker secrets (R2_ACCESS_KEY_ID / R2_SECRET_ACCESS_KEY or AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY) when omitted.

To mount by binding without passing credentials into the container, add an r2_buckets binding and export ContainerProxy from the Worker entrypoint (mount buckets guide):

[[r2_buckets]]
binding = "MY_BUCKET"
bucket_name = "my-r2-bucket"
import { ContainerProxy } from "@cloudflare/sandbox";
export { ContainerProxy };

Then:

await sandbox.mountBucket("MY_BUCKET", "/data");

Mount once per sandbox: mounted buckets are visible across sessions because they share the filesystem (mount buckets guide).

1.0 cannot mount through an R2 binding alone; use the R2 S3 API endpoint and API token credentials (Move bucket mounts, S3Mount API):

S3Mount does not accept an R2 binding. Use the R2 S3 API endpoint with R2 API credentials.

The S3Mount API summarises the flow:

S3Mount mounts an S3-compatible bucket, or a prefix in one, at a path in a running container. The container runs s3fs, which sends storage requests to S3Gateway in your Worker. S3Gateway checks each request and signs it with credentials that the container never receives.

Requirements include FUSE 3 and s3fs in the image and:

export { S3Gateway } from "@cloudflare/sandbox";

Do not route HTTP traffic to S3Gateway (S3Mount API).

Credentials: R2 tokens, Worker secrets, and credentialProxy

Section titled “Credentials: R2 tokens, Worker secrets, and credentialProxy”

For endpoint mounts, the SDK uses s3fs-fuse, which expects S3-style credentials. For R2, create API tokens in the dashboard and supply them with AWS variable names (Environment variables):

When mounting S3-compatible object storage, the SDK uses s3fs-fuse under the hood, which requires AWS-style credentials. For R2, generate API tokens from the Cloudflare dashboard and provide them using AWS environment variable names.

Typical setup:

wrangler secret put AWS_ACCESS_KEY_ID
wrangler secret put AWS_SECRET_ACCESS_KEY

The SDK can auto-detect AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY (and also R2_ACCESS_KEY_ID / R2_SECRET_ACCESS_KEY on remote endpoint mounts per the mount buckets guide) when you omit explicit credentials in mountBucket().

credentialProxy and ContainerProxy (0.x endpoint mounts)

Section titled “credentialProxy and ContainerProxy (0.x endpoint mounts)”

Without credentialProxy, s3fs may write credentials to a password file inside the container—a risk if the workload is untrusted. Setting credentialProxy: true keeps real credentials in the Durable Object, which re-signs outbound S3 traffic (mount buckets guide):

Set credentialProxy: true to keep credentials out of the container entirely. Instead of passing real credentials into the container, the Durable Object intercepts all outbound S3 requests at the network layer, re-signs them with the real credentials, and forwards them upstream.

This requires ContainerProxy exported from the Worker; otherwise the mount fails.

In 1.0, credentialProxy is removed—S3Gateway always signs requests (Move bucket mounts).

The Mount R2 buckets with FUSE example passes AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY into the container environment and sets enableInternet: true so tigrisfs can reach the R2 endpoint.

Prefix mounts, read-only access, and other mount options

Section titled “Prefix mounts, read-only access, and other mount options”

Expose only part of a bucket at the mount point. In 0.x, prefix must start with / (mount buckets guide):

await sandbox.mountBucket("MY_BUCKET", "/images", {
prefix: "/uploads/images/",
});

Objects appear at the mount path without the prefix segment in the path (same doc).

In 1.0, use keyPrefix without a leading /; S3Mount adds the trailing slash (S3Mount API).

await sandbox.mountBucket("MY_BUCKET", "/data", { readOnly: true });

Writes fail with a read-only filesystem error (mount buckets guide). In 1.0, set access: "read-only" or "read-write" (required) on the mount request.

await sandbox.unmountBucket("/data");

Mounted buckets are automatically unmounted when the sandbox is destroyed; manual unmount is optional (Storage API). In 1.0, unmount() throws S3_MOUNT_BUSY while a process still uses the path (S3Mount API).

Local development: FUSE, localBucket, and MinIO

Section titled “Local development: FUSE, localBucket, and MinIO”

Local Development for containers states:

Miniflare automatically grants local containers the Docker privileges required for Filesystem in Userspace (FUSE).

FUSE works when Docker runs in a VM (macOS, WSL) or on Linux rootless Docker with /dev/fuse. Rootful Docker on Linux does not support FUSE by default during local development.

With localBucket: true, the SDK syncs the R2 binding periodically rather than using a direct FUSE mount (mount buckets guide):

During local development, files are synchronized between R2 and the container using a periodic sync process rather than a direct filesystem mount.

Implications include a synchronization window after writes and caution with high-frequency writes to the same path from both sides. Production uses a direct filesystem mount with no sync delay.

For Sandbox 1.0 local work, use an S3-compatible server on the machine (for example MinIO) as described under Develop locally in Mount an R2 bucket.

Mounted filesystem behavior and performance

Section titled “Mounted filesystem behavior and performance”

Treat a mount as network-backed object storage, not a local disk.

The S3Mount API lists important semantics:

  • Renaming a file copies the object and deletes the original.
  • File locks, hard links, ownership, permissions, and atomic replacement do not behave like a local filesystem.
  • s3fs caches metadata (default 900 seconds); another client’s new or changed objects may not appear immediately unless you tune s3fsOptions (for example stat_cache_expire, disable_noobj_cache).
  • Snapshots do not include mounted directories.

The mount buckets guide recommends copying hot files to /workspace for speed, then copying results back to the bucket.

The Data persistence with R2 tutorial mounts /data, writes results with normal file I/O, destroys the sandbox, and still reads objects from R2—illustrating:

Automatic data persistence across sandbox lifecycles

Core call pattern:

await sandbox.mountBucket("my-data-bucket", "/data", {
endpoint: "https://YOUR_ACCOUNT_ID.r2.cloudflarestorage.com",
});

Replace YOUR_ACCOUNT_ID with the account ID from R2 > Overview in the dashboard (same tutorial).

Symptom Typical cause What docs recommend
R2 binding "MY_BUCKET" not found Binding missing or wrong name passed to mountBucket() Use binding name from wrangler.toml, not dashboard bucket name (mount buckets guide)
MissingCredentialsError endpoint set but no secrets Set R2_* or AWS_* secrets (mount buckets guide)
S3FSMountError: mount failed Bad endpoint, credentials, missing ContainerProxy, or network Verify binding, exports, bucket existence (mount buckets guide)
Mount path already in use Second mount on same path unmountBucket() or choose another path
Mount fails after interceptAllOutboundHttp() Catch-all intercept steals storage traffic Call mount() before the catch-all (Move bucket mounts, S3Mount API)
S3_MOUNT_CONFLICT (1.0) Different settings on same path unmount() first (S3Mount API)

Best practices from the mount buckets guide: mount early; prefer R2 binding mounts in 0.x production when possible; use read-only when you can; narrow exposure with prefix; never hardcode credentials; wrap mounts in try/catch.

For standalone Containers using tigrisfs, wait until mountpoint reports the mount ready before reading—see the startup script in Mount R2 buckets with FUSE—rather than assuming an immediate ls after backgrounding the FUSE process.

  1. Confirm wrangler.toml defines the expected r2_buckets binding (0.x binding mounts) or secrets and endpoint variables (endpoint / 1.0 S3Mount), per Mount buckets and Environment variables.

  2. Run wrangler dev on a Docker setup that meets FUSE support (or use localBucket: true / local MinIO per Mount an R2 bucket).

  3. Exercise mount and read/write: for the persistence tutorial, call POST /process, POST /destroy, then GET /results as in Data persistence with R2; for Containers FUSE, POST /run and inspect container logs (Mount R2 buckets with FUSE).

  4. In 1.0, call S3Mount.inspect() on the mount path if mounts fail intermittently (S3Mount API).

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about so it can be corrected or explained.