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

# Sandbox-Lebenszyklus

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

Eine Sandbox läuft weiter, bis ihr Zeitlimit abläuft oder bis Sie sie manuell stoppen. Standardmäßig bleibt eine neue Sandbox 5 Minuten aktiv. Sie können beim Erstellen der Sandbox ein anderes Zeitlimit festlegen, das Zeitlimit während der Ausführung aktualisieren, Sandbox-Informationen prüfen oder sie beenden, wenn Sie fertig sind.

<SandboxConfigHint />

## Eine Sandbox mit einem Zeitlimit erstellen

Legen Sie das Zeitlimit bei der Erstellung fest, wenn Sie wissen, wie lange die Arbeit laufen soll.

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

  // Timeout is in milliseconds.
  const sandbox = await Sandbox.create({ timeoutMs: 60_000 })

  await sandbox.kill()
  ```

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

  # Timeout is in seconds.
  sandbox = Sandbox.create(timeout=60)

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

## Das Zeitlimit aktualisieren

Sie können die Methode `setTimeout` verwenden, um zurückzusetzen, wie lange die Sandbox noch aktiv bleiben soll. Das ist nützlich, wenn die Benutzeraktivität fortgesetzt wird, nachdem das ursprüngliche Zeitlimit abgelaufen wäre.

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

  const sandbox = await Sandbox.create({ timeoutMs: 60_000 })

  await sandbox.setTimeout(300_000)

  await sandbox.kill()
  ```

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

  sandbox = Sandbox.create(timeout=60)

  sandbox.set_timeout(300)

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

## Sandbox-Informationen abrufen

Sie können die Methode `getInfo` in JavaScript oder die Methode `get_info` in Python verwenden, um die Sandbox-ID, die Vorlage, Metadaten, den aktuellen Zustand und die Ablaufzeit der Sandbox zu prüfen.

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

  const sandbox = await Sandbox.create({ timeoutMs: 60_000 })

  const info = await sandbox.getInfo()

  console.log(info.sandboxId)
  console.log(info.templateId)
  console.log(info.state)
  console.log(info.startedAt)
  console.log(info.endAt)

  await sandbox.kill()
  ```

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

  sandbox = Sandbox.create(timeout=60)

  info = sandbox.get_info()

  print(info.sandbox_id)
  print(info.template_id)
  print(info.state)
  print(info.started_at)
  print(info.end_at)

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

## Eine Sandbox beenden

Sie können die Methode `kill` verwenden, um eine Sandbox herunterzufahren, bevor ihr Zeitlimit abläuft, wenn Sie sie nicht mehr benötigen.

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

  const sandbox = await Sandbox.create({ timeoutMs: 60_000 })
  const sandboxId = sandbox.sandboxId

  await sandbox.kill()

  // Or kill by ID.
  await Sandbox.kill(sandboxId)
  ```

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

  sandbox = Sandbox.create(timeout=60)
  sandbox_id = sandbox.sandbox_id

  sandbox.kill()

  # Or kill by ID.
  Sandbox.kill(sandbox_id)
  ```
</CodeGroup>

## Nächste Schritte

* Um den Zustand einer Sandbox für die spätere Verwendung beizubehalten, siehe [Sandbox-Persistenz](/docs/de/guides/sandbox-persistence).
* Um wiederverwendbare gespeicherte Zustände zu erstellen, siehe [Sandbox-Snapshot](/docs/de/guides/sandbox-snapshot).
