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

# Time-out bij inactiviteit

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

Je kunt een **time-out bij inactiviteit** configureren voor je sandboxes, zodat ze automatisch worden gestopt of gepauzeerd wanneer er geen actieve verbindingen worden gedetecteerd. Dit helpt kosten te verlagen door ervoor te zorgen dat ongebruikte sandboxes niet onbeperkt blijven draaien.

<SandboxConfigHint />

<Note>
  De time-out bij inactiviteit wordt geconfigureerd via het veld `metadata` bij het maken van een sandbox. De sleutel is `idle_timeout` en de waarde is het aantal seconden (als een string).
</Note>

## Basisgebruik

Geef de sleutel `idle_timeout` door in het object `metadata` bij het maken van een sandbox. De waarde is de duur van de time-out bij inactiviteit in **seconden** (als een string). Wanneer er gedurende de opgegeven duur geen client met de sandbox is verbonden, wordt de sandbox automatisch beëindigd of gepauzeerd.

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

  // Create a sandbox that will be automatically killed after 60 seconds of inactivity.
  const sandbox = await Sandbox.create({
    metadata: {
      idle_timeout: '60',
    },
  })

  // The sandbox is running...
  // After 60 seconds with no active connections, it will be killed automatically.
  ```

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

  # Create a sandbox that will be automatically killed after 60 seconds of inactivity.
  sandbox = Sandbox.create(
      metadata={
          "idle_timeout": "60",
      },
  )

  # The sandbox is running...
  # After 60 seconds with no active connections, it will be killed automatically.
  ```
</CodeGroup>

## Hoe time-out bij inactiviteit werkt

De functie voor time-out bij inactiviteit bewaakt actieve verbindingen met je sandbox:

1. **Wanneer er geen verbindingen actief zijn** — wordt de eindtijd van de sandbox ingesteld op `current_time + idle_timeout_seconds`.
2. **Wanneer een verbinding weer actief wordt** — wordt de eindtijd van de sandbox hersteld naar de oorspronkelijke maximale levensduur van de sandbox.
3. **Wanneer de time-out bij inactiviteit verstrijkt zonder opnieuw verbinding te maken** — wordt de sandbox beëindigd (of gepauzeerd als `autoPause` is ingeschakeld).

Dit betekent dat een sandbox niet wordt gestopt zolang er ten minste één actieve client mee verbonden is (bijv. via `Sandbox.connect()` of open WebSocket/HTTP-verbindingen).

## Pauzeren in plaats van beëindigen

Standaard wordt een inactieve sandbox **beëindigd** wanneer de time-out bij inactiviteit verloopt. Als je wilt dat de sandbox in plaats daarvan wordt **gepauzeerd**, zodat je deze later kunt hervatten, schakel dan de optie `autoPause` in:

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

  // Create a sandbox that will be paused (instead of killed) after 60 seconds of inactivity.
  const sandbox = await Sandbox.create({
    metadata: {
      idle_timeout: '60',
    },
    autoPause: true,
  })

  // After 60 seconds of inactivity, the sandbox will be paused.
  // You can resume it later with Sandbox.connect().
  ```

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

  # Create a sandbox that will be paused (instead of killed) after 60 seconds of inactivity.
  sandbox = Sandbox.create(
      metadata={
          "idle_timeout": "60",
      },
      auto_pause=True,
  )

  # After 60 seconds of inactivity, the sandbox will be paused.
  # You can resume it later with Sandbox.connect().
  ```
</CodeGroup>

<Note>
  Wanneer `autoPause` is ingeschakeld, gaat de sandboxstatus bij een time-out door inactiviteit over naar `paused`. Je kunt later [connect](/docs/nl/guides/sandbox-connect) om de uitvoering te hervatten.
</Note>

## Combineren met andere metadata

De metadatasleutel `idle_timeout` kan worden gecombineerd met andere metadatasleutels die je mogelijk al gebruikt:

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

  const sandbox = await Sandbox.create({
    metadata: {
      idle_timeout: '120',
      env: 'production',
      userId: 'user-123',
    },
  })

  console.log('Sandbox ID:', sandbox.sandboxId)
  ```

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

  sandbox = Sandbox.create(
      metadata={
          "idle_timeout": "120",
          "env": "production",
          "user_id": "user-123",
      },
  )

  print("Sandbox ID:", sandbox.sandbox_id)
  ```
</CodeGroup>

## Beperkingen voor time-outs

| Beperking     | Waarde                 | Beschrijving                                                                                                                     |
| ------------- | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| **Minimum**   | 30 seconden            | Waarden onder 30 seconden worden behandeld als "inactiviteit uitgeschakeld" om snelle start/stop-cycli te voorkomen.             |
| **Standaard** | Uitgeschakeld (0)      | Als `idle_timeout` niet is opgegeven, is de functie uitgeschakeld en draait de sandbox totdat de maximale levensduur is bereikt. |
| **Maximum**   | Levensduur van sandbox | De time-out bij inactiviteit kan niet langer zijn dan de geconfigureerde `timeout` (maximale levensduur) van de sandbox.         |

<Warning>
  Als je `idle_timeout` instelt op een waarde onder de minimumdrempel (30 seconden), wordt de functie voor time-out bij inactiviteit **stilzwijgend uitgeschakeld** voor die sandbox. De sandbox blijft draaien totdat de maximale levensduur is verstreken.
</Warning>

## Time-out bij inactiviteit uitschakelen

Om de time-out bij inactiviteit voor een sandbox expliciet uit te schakelen, laat je simpelweg de sleutel `idle_timeout` weg uit de metadata, of stel je deze in op `"0"`:

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

  // No idle timeout — sandbox runs until its maximum lifetime.
  const sandbox = await Sandbox.create({
    metadata: {
      idle_timeout: '0',
    },
  })

  // Alternatively, omit idle_timeout entirely:
  const sandbox2 = await Sandbox.create()
  ```

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

  # No idle timeout — sandbox runs until its maximum lifetime.
  sandbox = Sandbox.create(
      metadata={
          "idle_timeout": "0",
      },
  )

  # Alternatively, omit idle_timeout entirely:
  sandbox2 = Sandbox.create()
  ```
</CodeGroup>

## Veelvoorkomende use-cases

### Kortdurende uitvoeringstaken

Gebruik een korte time-out bij inactiviteit voor sandboxes die eenmalige taken uitvoeren en niet hoeven te blijven bestaan nadat de client de verbinding verbreekt:

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

  const sandbox = await Sandbox.create({
    metadata: { idle_timeout: '60' },
  })

  // Execute code and get results...
  const result = await sandbox.runCode('print("Hello!")')

  // Disconnect — sandbox will be killed after 60 seconds of inactivity.
  await sandbox.kill()
  ```

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

  sandbox = Sandbox.create(
      metadata={"idle_timeout": "60"},
  )

  # Execute code and get results...
  result = sandbox.run_code('print("Hello!")')

  # Disconnect — sandbox will be killed after 60 seconds of inactivity.
  sandbox.kill()
  ```
</CodeGroup>

### Langlopende interactieve sessies

Gebruik een langere time-out bij inactiviteit voor sandboxes die worden gebruikt in interactieve sessies waarbij gebruikers tijdelijk kunnen weggaan:

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

  const sandbox = await Sandbox.create({
    metadata: { idle_timeout: '600' }, // 10 minutes
    autoPause: true,
  })

  // The sandbox will pause after 10 minutes of inactivity,
  // and can be resumed when the user returns.
  ```

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

  sandbox = Sandbox.create(
      metadata={"idle_timeout": "600"},  # 10 minutes
      auto_pause=True,
  )

  # The sandbox will pause after 10 minutes of inactivity,
  # and can be resumed when the user returns.
  ```
</CodeGroup>
