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

# Verouderde sandboxpersistentie

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

<Warning>
  Deze verouderde pagina wordt behouden voor gebruikers die nog steeds de 1.x- of beta-SDK-lijn gebruiken. Nieuwe SDK 2.x-integraties moeten de huidige sandboxdocumentatie volgen.
</Warning>

Met sandboxpersistentie kun je je sandbox pauzeren en deze later hervatten vanuit dezelfde toestand als waarin deze zich bevond toen je hem pauzeerde.

Dit omvat niet alleen de toestand van het bestandssysteem van de sandbox, maar ook het geheugen van de sandbox. Dit betekent alle actieve processen, geladen variabelen, data, enzovoort.

<SandboxConfigHint />

<Warning>
  Let op:

  * Het duurt ongeveer 4 seconden per 1 GB RAM om de sandbox te pauzeren.
  * Het duurt ongeveer 1 seconde om de sandbox te hervatten.
  * De data van een gepauzeerde sandbox worden permanent bewaard totdat je expliciet de methode `kill` aanroept.
</Warning>

## Sandbox pauzeren

Wanneer je een sandbox pauzeert, worden zowel het <Link href="/docs/nl/guides/sandbox-filesystem">bestandssysteem</Link> als de geheugenstatus van de sandbox opgeslagen. Dit omvat alle bestanden in het bestandssysteem van de sandbox en alle actieve processen, geladen variabelen, data, enzovoort.

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

  const sandbox = await Sandbox.create()
  console.log('Sandbox created', sandbox.sandboxId)

  // Pause the sandbox.
  // You can save the sandbox ID in your database
  // to resume the sandbox later
  const result = await sandbox.betaPause()
  console.log('Sandbox paused', sandbox.sandboxId, result)

  await sandbox.kill()
  ```

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

  sandbox = Sandbox.create()
  print('Sandbox created', sandbox.sandbox_id)

  # You can save the sandbox ID in your database
  # to resume the sandbox later
  sandbox.beta_pause()
  print('Sandbox paused', sandbox.sandbox_id)

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

<Warning>
  **Opmerking: korte overgangsperiode na het pauzeren**

  Pauzeren is een asynchrone bewerking. Na het aanroepen van `beta_pause()` pauzeert de sandbox op de achtergrond.

  Tijdens deze overgangsperiode, voordat het pauzeren is voltooid:

  * **Alleen-lezen-bewerkingen** (bijv. `get_info`, `list`): worden normaal geretourneerd; de status wordt weergegeven als `paused`
  * **Uitvoeringsbewerkingen** (bijv. `commands.run`, toegang tot openbare sandbox-URL's): geven fouten terug — dit is verwacht gedrag. Wacht tot het pauzeren is voltooid voordat je het opnieuw probeert (de tijd varieert afhankelijk van de geheugengrootte, zie de opmerking hierboven)
  * **Hervatbewerking** (`connect`): wacht automatisch tot het pauzeren is voltooid voordat de sandbox wordt hervat — handmatig pollen of opnieuw proberen is niet nodig
</Warning>

## Sandbox hervatten

Wanneer je een sandbox hervat, bevindt deze zich in dezelfde toestand als toen je hem pauzeerde.
Dit betekent dat alle bestanden in het bestandssysteem van de sandbox worden hersteld en dat alle actieve processen, geladen variabelen, data, enzovoort worden hersteld.

<Tip>
  Als je `connect()` direct aanroept na het aanroepen van `beta_pause()`, wacht `connect()` automatisch tot het pauzeren is voltooid voordat de sandbox wordt hervat. Handmatig pollen is niet vereist — het volledige proces is transparant voor de aanroeper.
</Tip>

<Warning>
  Als je probeert een sandbox te hervatten die is vernietigd of niet bestaat:

  * JavaScript SDK geeft `NotFoundError`
  * Python SDK geeft `NotFoundException`
</Warning>

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

  const sandbox = await Sandbox.create()
  console.log('Sandbox created', sandbox.sandboxId)

  // Pause the sandbox.
  // You can save the sandbox ID in your database
  // to resume the sandbox later
  const result = await sandbox.betaPause()
  console.log('Sandbox paused', sandbox.sandboxId, result)

  // Resume the sandbox.
  // Even if called before pausing completes, connect() automatically waits for the pause to finish.
  const resumedSandbox = await sandbox.connect()
  console.log('Sandbox resumed', resumedSandbox.sandboxId)

  await sandbox.kill()
  ```

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

  sandbox = Sandbox.create()
  print('Sandbox created', sandbox.sandbox_id)

  # Pause the sandbox.
  # You can save the sandbox ID in your database
  # to resume the sandbox later
  sandbox.beta_pause()
  print('Sandbox paused', sandbox.sandbox_id)

  # Resume the sandbox.
  # Even if called before pausing completes, connect() automatically waits for the pause to finish.
  connectedSandbox = sandbox.connect()
  print('Sandbox resumed', connectedSandbox.sandbox_id)

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

## Gepauzeerde sandboxes weergeven

Je kunt alle gepauzeerde sandboxes weergeven door de methode `Sandbox.list` aan te roepen en de queryparameter `state` mee te geven.
Meer informatie over het gebruik van de methode is te vinden in [Sandboxes weergeven](/docs/nl/guides/sandbox-list).

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

  const sandbox = await Sandbox.create()

  // List all paused sandboxes.
  const paginator = Sandbox.list({ query: { state: ['paused'] } })

  // Get all paused sandboxes.
  const sandboxes: SandboxInfo[] = []
  while (paginator.hasNext) {
    const items = await paginator.nextItems()
    sandboxes.push(...items)
  }

  console.log('all paused sandboxes', sandboxes)

  await sandbox.kill()
  ```

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

  sandbox = Sandbox.create()

  sandbox.beta_pause()
  print('Sandbox paused', sandbox.sandbox_id)

  # List all paused sandboxes.
  paginator = Sandbox.list(query=SandboxQuery(state=[SandboxState.PAUSED]))

  # Get all paused sandboxes.
  sandboxes: list[SandboxInfo] = []
  while paginator.has_next:
    items = paginator.next_items()
    sandboxes.extend(items)

  print('all paused sandboxes', sandboxes)

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

## Gepauzeerde sandboxes verwijderen

Je kunt gepauzeerde sandboxes verwijderen door de methode `kill` op de sandboxinstantie aan te roepen.

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

  const sandbox = await Sandbox.create()
  console.log('Sandbox created', sandbox.sandboxId)

  // Pause the sandbox.
  await sandbox.betaPause()

  // Kill the paused sandbox.
  await sandbox.kill()
  ```

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

  sandbox = Sandbox.create()

  # Pause the sandbox.
  sandbox.beta_pause()

  # Kill the paused sandbox.
  sandbox.kill()
  ```
</CodeGroup>

## Timeout van de sandbox

Wanneer je een sandbox hervat, wordt de timeout van de sandbox teruggezet naar de standaardtimeout van een sandbox: 5 minuten.

Je kunt als volgt een aangepaste timeout doorgeven aan de methode `Sandbox.connect()`:

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

  const sandbox = await Sandbox.create()

  const connectedSandbox = await Sandbox.connect(sandbox.sandboxId, { timeoutMs: 60 * 1000 })
  console.log('Sandbox connected', connectedSandbox.sandboxId)

  await sandbox.kill()
  ```

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

  sandbox = Sandbox.create()

  connectedSandbox = Sandbox.connect(sandbox.sandbox_id, timeout=60) # 60 seconds
  print('Sandbox connected', connectedSandbox.sandbox_id)

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

## Netwerk

Als je een service (bijvoorbeeld een server) binnen je sandbox hebt draaien en je de sandbox pauzeert, is de service van buitenaf niet toegankelijk en worden alle clients losgekoppeld.
Als je de sandbox hervat, is de service weer toegankelijk, maar moet je clients opnieuw verbinden.
