> ## Documentation Index
> Fetch the complete documentation index at: https://novita.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Object storage-bucket in sandbox mounten

export const SandboxConfigHint = () => {
  if (typeof document === "undefined") {
    return null;
  } else {
    return <Note>Before running the example code in this document, please ensure you have properly configured environment variables. For details, please refer to <a href="/docs/nl/guides/sandbox-your-first-agent-sandbox#configure-environment-variables">Configure Environment Variables</a>.</Note>;
  }
};

Elke sandbox-instantie wordt standaard ingericht met 20 GB aan tijdelijke systeemschijfopslag voor tijdelijke gegevensbewerkingen. <u>Bij beëindiging of timeout van de sandbox worden alle gegevens binnen deze opslagruimte automatisch verwijderd</u>. Daarom moeten persistente gegevens die langdurig bewaard moeten blijven, worden opgeslagen in externe cloudopslagdiensten.

<Tip>
  Specificaties voor sandboxopslagtoewijzing kunnen worden gewijzigd. Raadpleeg de documentatie voor [Prijzen](/docs/nl/guides/sandbox-pricing) voor de huidige resourcetoewijzingen en bijbehorende kosten.
</Tip>

Object Storage is een zeer schaalbare, duurzame en kostenefficiënte cloudopslagarchitectuur die wordt aangeboden door grote cloudserviceproviders. Binnen sandboxomgevingen kan object storage via twee primaire methoden worden benaderd: directe programmatische interactie via cloudprovider-SDK's of CLI-tools, of via FUSE-implementaties (Filesystem in Userspace) die object storage-buckets presenteren als standaard POSIX-compatibele filesystem-mounts.

<Tip>
  [FUSE (Filesystem in Userspace)](https://www.kernel.org/doc/html/next/filesystems/fuse.html) is een kernelmodule en userspace-bibliotheek waarmee volledig functionele bestandssystemen in userspace-applicaties kunnen worden geïmplementeerd. Dit framework biedt een abstractielaag die externe cloudopslagdiensten presenteert als standaard bestandssysteemhiërarchieën, waardoor transparante bestandsbewerkingen via conventionele POSIX-interfaces mogelijk zijn.
</Tip>

Deze documentatie biedt uitgebreide richtlijnen voor het integreren van object storage-buckets van toonaangevende cloudserviceproviders in sandboxomgevingen via technieken voor het mounten van bestandssystemen.

<Warning>
  FUSE-gebaseerde object storage-mounts introduceren aanzienlijke I/O prestatie-overhead door netwerklatentie en protocolvertaallagen. Applicaties met strenge prestatie-eisen zouden deze aanpak moeten vermijden. Bovendien missen FUSE-bestandssysteembewerkingen de atomiciteitsgaranties die inherent zijn aan native object storage-API's, waardoor potentiële race conditions ontstaan waarbij lokale bestandssysteembewerkingen kunnen slagen terwijl de bijbehorende externe bewerkingen mislukken, wat resulteert in gegevensinconsistentie.

  Deze mount-aanpak is optimaal voor read-heavy workloads met weinig schrijfbewerkingen en soepele prestatie-eisen. Voor prestatiekritische applicaties of patronen met frequente schrijfbewerkingen wordt directe integratie met cloudprovider-SDK's of native REST API's sterk aanbevolen.
</Warning>

<SandboxConfigHint />

## Amazon S3

Amazon S3-buckets kunnen worden gemount als POSIX-compatibele bestandssystemen met [s3fs-fuse](https://github.com/s3fs-fuse/s3fs-fuse), een FUSE-gebaseerde bestandssysteemimplementatie die toegang tot S3-buckets biedt via standaard bestandsbewerkingen.

Het s3fs-fuse-pakket kan tijdens het maken van een [sandboxtemplate](/docs/nl/guides/sandbox-template-quickstart) worden geïntegreerd door installatiecommando's op te nemen in de `novita.Dockerfile`, of dynamisch worden geïnstalleerd binnen actieve sandbox-instanties voor ad-hocvereisten.

De volgende `novita.Dockerfile` demonstreert de integratie van s3fs-fuse tijdens het bouwen van de template:

<CodeGroup>
  ```dockerfile novita.Dockerfile icon="docker" theme={"system"}
  # Compatible with Debian-based distributions
  FROM ubuntu:latest

  # Critical: s3fs versions below 1.93 contain known mounting issues. Ensure version compatibility.
  RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y s3fs
  ```
</CodeGroup>

De volgende implementatie demonstreert het programmatisch mounten van een S3-bucket binnen sandboxomgevingen met s3fs-fuse:

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Sandbox } from 'novita-sandbox'

  const TEMPLATE_ID = process.env.NOVITA_TEMPLATE_ID
  const AWS_ACCESS_KEY_ID = process.env.AWS_ACCESS_KEY_ID
  const AWS_SECRET_ACCESS_KEY = process.env.AWS_SECRET_ACCESS_KEY
  const AWS_BUCKET_NAME = process.env.AWS_BUCKET_NAME
  const AWS_REGION = process.env.AWS_REGION
  if (!TEMPLATE_ID || !AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY || !AWS_BUCKET_NAME || !AWS_REGION) {
      throw new Error('Required environment variables not configured: NOVITA_TEMPLATE_ID, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_BUCKET_NAME, AWS_REGION')
  }

  const MOUNT_DIRECTORY = "/mnt/s3-bucket"

  const sandbox = await Sandbox.create(TEMPLATE_ID)

  // Initialize mount point directory structure
  await sandbox.files.makeDir(MOUNT_DIRECTORY)

  // Configure s3fs credentials using standard credential file location
  // s3fs-fuse reads AWS credentials from /root/.passwd-s3fs by default
  await sandbox.files.write('/root/.passwd-s3fs', `${AWS_ACCESS_KEY_ID}:${AWS_SECRET_ACCESS_KEY}`)

  // Enforce secure credential file permissions (owner read-only)
  await sandbox.commands.run('sudo chmod 600 /root/.passwd-s3fs')

  // Execute S3 bucket mount operation with optimized parameters
  // Configuration parameters:
  // - allow_other: Enable cross-user filesystem access
  // - endpoint: Specify the AWS region endpoint for your bucket
  // Reference: https://manpages.ubuntu.com/manpages/noble/en/man1/s3fs.1.html
  const mountOptions = `allow_other,endpoint=${AWS_REGION}`
  await sandbox.commands.run(`sudo s3fs ${AWS_BUCKET_NAME} ${MOUNT_DIRECTORY} -o ${mountOptions}`)

  // Validate mount functionality with write operation
  await sandbox.files.write(`${MOUNT_DIRECTORY}/test-file.txt`, 'test-file-content')

  // Verify mount integrity through read operation
  const content = await sandbox.files.read(`${MOUNT_DIRECTORY}/test-file.txt`)
  console.log(content)

  await sandbox.kill()
  ```

  ```python Python icon="python" theme={"system"}
  import os
  from novita_sandbox.core import Sandbox

  TEMPLATE_ID = os.environ.get("NOVITA_TEMPLATE_ID")
  AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID")
  AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY")
  AWS_BUCKET_NAME = os.environ.get("AWS_BUCKET_NAME")
  AWS_REGION = os.environ.get("AWS_REGION")
  if not TEMPLATE_ID or not AWS_ACCESS_KEY_ID or not AWS_SECRET_ACCESS_KEY or not AWS_BUCKET_NAME or not AWS_REGION:
      raise ValueError("Required environment variables not configured: NOVITA_TEMPLATE_ID, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_BUCKET_NAME, AWS_REGION")

  MOUNT_DIRECTORY = "/mnt/s3-bucket"

  sandbox = Sandbox.create(TEMPLATE_ID)

  # Initialize mount point directory structure
  sandbox.files.make_dir(MOUNT_DIRECTORY)

  # Configure s3fs credentials using standard credential file location
  # s3fs-fuse reads AWS credentials from /root/.passwd-s3fs by default
  # Custom credential paths require explicit specification via -o passwd_file parameter
  sandbox.files.write("/root/.passwd-s3fs", f"{AWS_ACCESS_KEY_ID}:{AWS_SECRET_ACCESS_KEY}")

  # Enforce secure credential file permissions (owner read-only)
  sandbox.commands.run("sudo chmod 600 /root/.passwd-s3fs")

  # Execute S3 bucket mount operation with optimized parameters
  # Configuration parameters:
  # - allow_other: Enable cross-user filesystem access
  # - endpoint: Specify the AWS region endpoint for your bucket
  # Reference: https://manpages.ubuntu.com/manpages/noble/en/man1/s3fs.1.html
  mount_options = f"allow_other,endpoint={AWS_REGION}"
  sandbox.commands.run(f"sudo s3fs {AWS_BUCKET_NAME} {MOUNT_DIRECTORY} -o {mount_options}")

  # Validate mount functionality with write operation
  write_result = sandbox.files.write(f"{MOUNT_DIRECTORY}/test-file.txt", "test-file-content")

  # Verify mount integrity through read operation
  content = sandbox.files.read(f"{MOUNT_DIRECTORY}/test-file.txt")
  print("File content:", content)

  sandbox.kill()
  ```
</CodeGroup>
