> ## Documentation Index
> Fetch the complete documentation index at: https://docs.novita.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Timeout Handle

Every sandbox has a **maximum lifetime**, controlled by the `timeout` setting. When the timeout expires, the sandbox is stopped. By default, a new sandbox stays alive for **5 minutes**.

<Note>
  **Timeout vs. Idle timeout — don't confuse them:**

  * **Timeout** is the maximum lifetime of the sandbox. It starts counting down from creation, regardless of activity, and always takes effect when it expires.
  * **Idle timeout** only fires when no client is connected for the configured duration.
</Note>

## Create a sandbox with a timeout

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

  const novita = new Novita()
  const sandbox = await novita.sandbox.create({ timeoutMs: 60_000 })

  await sandbox.kill()
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox import Novita

  novita = Novita()
  sandbox = novita.sandbox.create(timeout=60)

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

## Update the timeout

You can use `setTimeout` / `set_timeout` to reset how much longer the sandbox should stay alive.

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

  const novita = new Novita()
  const sandbox = await novita.sandbox.create({ timeoutMs: 60_000 })

  await sandbox.setTimeout(300_000)
  await sandbox.kill()
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox import Novita

  novita = Novita()
  sandbox = novita.sandbox.create(timeout=60)

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

## Lifecycle behavior

You can combine `timeout` with `lifecycle` to choose whether the sandbox is killed or paused when the timeout expires.

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

  const novita = new Novita()
  const sandbox = await novita.sandbox.create({
    timeoutMs: 300_000,
    lifecycle: {
      onTimeout: 'pause',
      autoResume: true,
    },
  })
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox import Novita

  novita = Novita()
  sandbox = novita.sandbox.create(
      timeout=300,
      lifecycle={
          'on_timeout': 'pause',
          'auto_resume': True,
      },
  )
  ```
</CodeGroup>

If you do not pass `lifecycle`, the sandbox is killed when the timeout expires.
