Skip to content

Cloud buckets

A sandbox can mount an object-storage bucket through a FUSE client. The files then appear under an ordinary directory and can be used by commands and applications inside the sandbox.

The example below uses s3fs, so add it to your template with aptInstall("s3fs"). Keeping the client in the template makes sandbox startup faster and avoids installing system packages at runtime.

Mount an S3-compatible bucket

Create the sandbox first, then pass the bucket name, endpoint, and credentials to this helper:

mjs
async function mountS3Bucket(
  sandbox,
  { bucket, endpoint, accessKey, secretKey, mountPoint = "/home/user/bucket" },
) {
  const result = await sandbox.commands.run(
    `set -eu
credentials="$HOME/.passwd-s3fs"
trap 'rm -f "$credentials"' EXIT
mkdir -p "$S3_MOUNT_POINT"
umask 077
printf '%s:%s' "$S3_ACCESS_KEY" "$S3_SECRET_KEY" > "$credentials"
s3fs "$S3_BUCKET" "$S3_MOUNT_POINT" \
  -o passwd_file="$credentials" \
  -o url="$S3_ENDPOINT" \
  -o use_path_request_style
printf 'Mounted %s at %s\n' "$S3_BUCKET" "$S3_MOUNT_POINT"`,
    {
      envs: {
        S3_BUCKET: bucket,
        S3_ENDPOINT: endpoint,
        S3_ACCESS_KEY: accessKey,
        S3_SECRET_KEY: secretKey,
        S3_MOUNT_POINT: mountPoint,
      },
    },
  );
  console.log(result.stdout);
}

After the mount completes, programs can read and write files under /home/user/bucket. Unmount it with fusermount -u /home/user/bucket when a long-running sandbox no longer needs the bucket.

Use the endpoint supplied by your object-storage provider. Selectel S3 and other S3-compatible services require path-style requests, which the example enables with use_path_request_style.

Credentials

Do not put access keys into the template. Pass them to the sandbox at runtime or fetch short-lived credentials from your own secret store. The helper writes the credentials file with owner-only permissions and removes it immediately after s3fs starts.

FUSE exposes object storage as a filesystem, but it does not add POSIX semantics to the storage service. Avoid workloads that depend on atomic rename, file locking, or many small random writes unless your provider documents that behavior.