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

# Objektspeicher-Bucket in Sandbox einbinden

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/de/guides/sandbox-your-first-agent-sandbox#configure-environment-variables">Configure Environment Variables</a>.</Note>;
  }
};

Jede Sandbox-Instanz wird standardmäßig mit 20 GB flüchtigem Systemfestplattenspeicher für temporäre Datenoperationen bereitgestellt. <u>Bei Beendigung oder Timeout der Sandbox werden alle Daten in diesem Speicherbereich automatisch gelöscht</u>. Daher sollten persistente Daten, die langfristig aufbewahrt werden müssen, in externen Cloud-Speicherdiensten gespeichert werden.

<Tip>
  Die Spezifikationen für die Speicherzuweisung von Sandboxes können sich ändern. Aktuelle Ressourcenzuweisungen und zugehörige Kosten finden Sie in der Dokumentation zu [Preise](/docs/de/guides/sandbox-pricing).
</Tip>

Objektspeicher ist eine hochskalierbare, langlebige und kosteneffiziente Cloud-Speicherarchitektur, die von großen Cloud-Service-Providern angeboten wird. In Sandbox-Umgebungen kann auf Objektspeicher über zwei primäre Methoden zugegriffen werden: direkte programmatische Interaktion über SDKs oder CLI-Dienstprogramme des Cloud-Providers oder über FUSE-Implementierungen (Filesystem in Userspace), die Objektspeicher-Buckets als standardmäßige POSIX-konforme Dateisystem-Mounts darstellen.

<Tip>
  [FUSE (Filesystem in Userspace)](https://www.kernel.org/doc/html/next/filesystems/fuse.html) ist ein Kernelmodul und eine Userspace-Bibliothek, die die Implementierung voll funktionsfähiger Dateisysteme in Userspace-Anwendungen ermöglicht. Dieses Framework stellt eine Abstraktionsschicht bereit, die entfernte Cloud-Speicherdienste als standardmäßige Dateisystemhierarchien darstellt und transparente Dateioperationen über konventionelle POSIX-Schnittstellen ermöglicht.
</Tip>

Diese Dokumentation bietet umfassende Anleitungen zur Integration von Objektspeicher-Buckets führender Cloud-Service-Provider in Sandbox-Umgebungen mithilfe von Dateisystem-Mounting-Techniken.

<Warning>
  FUSE-basierte Objektspeicher-Mounts verursachen aufgrund von Netzwerklatenz und Protokollübersetzungsschichten einen erheblichen I/O-Performance-Overhead. Anwendungen mit strengen Performance-Anforderungen sollten diesen Ansatz vermeiden. Darüber hinaus fehlen FUSE-Dateisystemoperationen die Atomaritätsgarantien, die nativen Objektspeicher-APIs innewohnen. Dadurch können potenzielle Race Conditions entstehen, bei denen lokale Dateisystemoperationen erfolgreich sind, während entsprechende entfernte Operationen fehlschlagen, was zu Dateninkonsistenzen führt.

  Dieser Mounting-Ansatz ist optimal für leseintensive Workloads mit seltenen Schreiboperationen und lockeren Performance-Einschränkungen. Für performancekritische Anwendungen oder häufige Schreibmuster wird die direkte Integration mithilfe von SDKs des Cloud-Providers oder nativen REST-APIs dringend empfohlen.
</Warning>

<SandboxConfigHint />

## Amazon S3

Amazon S3-Buckets können mit [s3fs-fuse](https://github.com/s3fs-fuse/s3fs-fuse), einer FUSE-basierten Dateisystemimplementierung, die Zugriff auf S3-Buckets über standardmäßige Dateioperationen bietet, als POSIX-konforme Dateisysteme eingebunden werden.

Das Paket s3fs-fuse kann während der Erstellung einer [Sandbox-Vorlage](/docs/de/guides/sandbox-template-quickstart) integriert werden, indem Installationsbefehle in `novita.Dockerfile` aufgenommen werden, oder dynamisch in aktiven Sandbox-Instanzen für Ad-hoc-Anforderungen installiert werden.

Das folgende `novita.Dockerfile` demonstriert die Integration von s3fs-fuse während der Vorlagenerstellung:

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

Die folgende Implementierung demonstriert das programmatische Mounten von S3-Buckets in Sandbox-Umgebungen mithilfe von 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>
