# Sandbox Lifecycle - Documentation

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown is available with `Accept: text/markdown` and `.md` URL variants.

Source: /docs/guides/sandbox-lifecycle

# Sandbox Lifecycle

A sandbox keeps running until its timeout expires or until you stop it manually. By default, a new sandbox stays alive for 5 minutes. You can set a different timeout when creating the sandbox, update the timeout while it is running, inspect sandbox information, or kill it when you are done.

##

[​](#create-a-sandbox-with-a-timeout)

Create a sandbox with a timeout

Set the timeout at creation time when you know how long the work should run.

JavaScript & TypeScript

Python

```
import { Sandbox } from 'novita-sandbox/code-interpreter'

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

await sandbox.kill()
```

```
from novita_sandbox.code_interpreter import Sandbox

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

sandbox.kill()
```

##

[​](#update-the-timeout)

Update the timeout

You can use the `setTimeout` method to reset how much longer the sandbox should stay alive. This is useful when user activity continues after the original timeout would have expired.

JavaScript & TypeScript

Python

```
import { Sandbox } from 'novita-sandbox/code-interpreter'

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

await sandbox.setTimeout(300_000)

await sandbox.kill()
```

```
from novita_sandbox.code_interpreter import Sandbox

sandbox = Sandbox.create(timeout=60)

sandbox.set_timeout(300)

sandbox.kill()
```

##

[​](#get-sandbox-information)

Get sandbox information

You can use the `getInfo` method in JavaScript or `get_info` method in Python to inspect the sandbox ID, template, metadata, current state, and expiration time.

JavaScript & TypeScript

Python

```
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()
```

```
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()
```

##

[​](#kill-a-sandbox)

Kill a sandbox

You can use the `kill` method to shut down a sandbox before its timeout expires when you no longer need it.

JavaScript & TypeScript

Python

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

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

##

[​](#next-steps)

Next steps

- To keep a sandbox state for later use, see [Sandbox Persistence](/docs/guides/sandbox-persistence).

- To create reusable saved states, see [Sandbox Snapshot](/docs/guides/sandbox-snapshot).

Last modified on June 8, 2026
