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

# Levenscyclus van sandbox

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

Een sandbox blijft actief totdat de timeout verloopt of totdat je deze handmatig stopt. Standaard blijft een nieuwe sandbox 5 minuten actief. Je kunt een andere timeout instellen wanneer je de sandbox maakt, de timeout bijwerken terwijl deze actief is, sandboxinformatie bekijken of de sandbox beëindigen wanneer je klaar bent.

<SandboxConfigHint />

## Maak een sandbox met een timeout

Stel de timeout in bij het maken wanneer je weet hoe lang het werk moet worden uitgevoerd.

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

## Werk de timeout bij

Je kunt de methode `setTimeout` gebruiken om opnieuw in te stellen hoe lang de sandbox nog actief moet blijven. Dit is handig wanneer gebruikersactiviteit doorgaat nadat de oorspronkelijke timeout zou zijn verlopen.

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

## Haal sandboxinformatie op

Je kunt de methode `getInfo` in JavaScript of de methode `get_info` in Python gebruiken om de sandbox-ID, template, metadata, huidige status en vervaltijd te bekijken.

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

## Beëindig een sandbox

Je kunt de methode `kill` gebruiken om een sandbox af te sluiten voordat de timeout verloopt, wanneer je deze niet langer nodig hebt.

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

## Volgende stappen

* Zie [Sandbox Persistence](/docs/nl/guides/sandbox-persistence) om de status van een sandbox te bewaren voor later gebruik.
* Zie [Sandbox Snapshot](/docs/nl/guides/sandbox-snapshot) om herbruikbare opgeslagen statussen te maken.
