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

# Keep Alive

When `keepAlive` is enabled, the box stays on between sessions instead of auto-pausing when idle. Use it when you need a box to remain continuously available, for example to host a server, keep a long-running agent ready, or preserve an always-on development environment.

For most workloads, the default Box lifecycle is still the better choice. Boxes auto-pause when idle and are more cost-efficient for bursty workloads unless `keepAlive` is enabled.

> [!NOTE]
>
> Keep-alive boxes require a paid plan. On the free plan, creating a box with `keepAlive: true` fails with a `403` error.

***

## Create a keep-alive box

Use `keepAlive: true` when creating the box:

```typescript box.ts theme={"system"}
import { Box } from "@upstash/box"

const box = await Box.create({
  runtime: "node",
  size: "medium",
  keepAlive: true,
})
```

```python box.py theme={"system"}
from upstash_box import Box

box = Box.create(
    runtime="node",
    size="medium",
    keep_alive=True,
)
```

You can combine keep-alive with all normal Box features, including agent, git, shell, filesystem, public URLs, and snapshots.

***

## Sizes and specs

Boxes with `keepAlive` enabled use the same Box sizes as any other box. Pick the size with the `size` option when creating the box or in the Console during box creation.

| Size | CPU | Memory | Storage |
| - | - | - | - |
| `small` | 2 vCPU | 4 GB | 10 GB |
| `medium` | 4 vCPU | 8 GB | 20 GB |
| `large` | 8 vCPU | 16 GB | 30 GB |

The selected size determines the box's available CPU, RAM, and workspace storage whether `keepAlive` is enabled or not.

***

## Lifecycle differences

| | Default behavior | With `keepAlive: true` |
| - | - | - |
| **Idle behavior** | Auto-pauses when idle | Stays on |
| **Pause / resume** | Supported | Not supported |
| **Best for** | Bursty workloads, task runners, on-demand agents | Always-on servers, long-running agents, warm environments |
| **Billing model** | Active usage based | Open-time / always-on based |

If you do not need the box to remain continuously available, keep `keepAlive` disabled.

***

## Init command

A keep-alive box can run an init command, a startup script the box runs once each time its container starts.

```typescript box.ts theme={"system"}
const box = await Box.create({
  runtime: "node",
  keepAlive: true,
  initCommand: "npm install && npm run dev",
})
```

```python box.py theme={"system"}
box = Box.create(
    runtime="node",
    keep_alive=True,
    init_command="npm install && npm run dev",
)
```

Init commands are not a keep-alive feature. Every box can have one, and get, set, and delete work on any box, including a paused one. See [Create a Box](https://upstash.com/docs/box/overall/quickstart#init-command).

***

## Console

In the Upstash Console you can:

* enable **Keep alive** while creating a box
* choose the box **Size**
* manage the **Init Command** later from the box settings page (available on every box, not only keep-alive ones)

***

## When to use keep alive

Use keep-alive when the box itself needs to stay available between requests:

* hosting a dev server or app with a public URL
* keeping an agent warm for low-latency use
* preserving a long-running environment with startup automation

Avoid keep-alive when you only need a reusable workspace. In those cases, the default box lifecycle plus [Snapshots](https://upstash.com/docs/box/overall/snapshots) is usually enough.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.