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

# Daten aus der Sandbox herunterladen

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

Sie können die Methode `files.read()` verwenden, um Daten aus der Sandbox herunterzuladen.

<SandboxConfigHint />

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

  const sandbox = await Sandbox.create()

  // Create a file in the sandbox for testing
  const filePathInSandbox = '/tmp/test-file'
  await sandbox.files.write(filePathInSandbox, "test-file-content")

  // Read file from sandbox
  const content = await sandbox.files.read(filePathInSandbox)

  // Write file to local filesystem
  const localFilePath = './local-test-file'
  fs.writeFileSync(localFilePath, content)

  await sandbox.kill()
  ```

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

  sandbox = Sandbox.create()

  # Create a file in the sandbox for testing
  file_path_in_sandbox = '/tmp/test-file'
  sandbox.files.write(file_path_in_sandbox, "test-file-content")

  # Read file from sandbox
  content = sandbox.files.read(file_path_in_sandbox)

  # Write file to local filesystem
  local_file_path = './local-test-file'
  with open(local_file_path, 'w') as file:
    file.write(content)

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

## Download mit vorsignierter URL

Vorsignierte Download-URLs ermöglichen es Benutzern, Dateien sicher aus Umgebungen herunterzuladen, die keine Novita-SDK-Anmeldedaten besitzen, z. B. Webbrowser.
Erstellen Sie die Sandbox mit der Option `secure: true`, und verwenden Sie anschließend das SDK auf Ihrem vertrauenswürdigen Backend, um die Download-URL zu generieren. Geben Sie sie nur an Benutzer zurück, die von Ihrer Anwendung autorisiert wurden, und legen Sie eine kurze Ablaufzeit fest. Die URL dient bis zu ihrem Ablauf als temporärer Bearer-Zugangsnachweis.

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

  const sandbox = await Sandbox.create({ secure: true })

  // Create a test file in the sandbox (requires SDK authentication)
  const filePathInSandbox = '/tmp/test-file'
  await sandbox.files.write(filePathInSandbox, 'test-file-content')

  // Generate pre signed download URL (valid for 120 seconds, optional)
  const publicDownloadUrl = await sandbox.downloadUrl(filePathInSandbox, {
    useSignatureExpiration: 120, // optional, in seconds
  })

  // Simulate "browser/unauthorized environment": without API key, directly GET download
  const res = await fetch(publicDownloadUrl)
  if (!res.ok) {
    throw new Error(`Download failed: ${res.status} ${await res.text()}`)
  }
  const content = await res.text()

  // Write to local file
  const localFilePath = './local-test-file'
  fs.writeFileSync(localFilePath, content)
  console.log(content)

  await sandbox.kill()
  ```

  ```python Python icon="python" theme={"system"}
  from pathlib import Path

  import requests
  from novita_sandbox.code_interpreter import Sandbox

  sandbox = Sandbox.create(secure=True)

  # Create a test file in the sandbox (requires SDK authentication)
  file_path_in_sandbox = '/tmp/test-file'
  sandbox.files.write(file_path_in_sandbox, 'test-file-content')

  # Generate pre signed download URL (valid for 120 seconds, optional)
  signed_url = sandbox.download_url(
      path=file_path_in_sandbox,
      use_signature_expiration=120  # optional, in seconds
  )

  # Simulate "browser/unauthorized environment": without API key, directly GET download
  response = requests.get(signed_url, timeout=60)
  response.raise_for_status()
  content = response.text

  # Write to local file
  local_file_path = Path('./local-test-file')
  local_file_path.write_text(content)
  print(content)

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