Skip to main content
You can configure an idle timeout for your sandboxes to automatically stop or pause when no active connections are detected. This helps reduce costs by ensuring unused sandboxes are not running indefinitely.
The idle timeout is configured via the metadata field when creating a sandbox. The key is idle_timeout and the value is the number of seconds (as a string).

Basic usage

Pass the idle_timeout key in the metadata object when creating a sandbox. The value is the idle timeout duration in seconds (as a string). When no client is connected to the sandbox for the specified duration, the sandbox will be automatically killed or paused.

How idle timeout works

The idle timeout feature monitors active connections to your sandbox:
  1. When no connections are active — the sandbox’s end time is set to current_time + idle_timeout_seconds.
  2. When a connection becomes active again — the sandbox’s end time is restored to the original maximum sandbox lifetime.
  3. When the idle timeout elapses without any reconnection — the sandbox is killed (or paused if autoPause is enabled).
This means a sandbox won’t be stopped as long as there is at least one active client connected to it (e.g., via Sandbox.connect() or open WebSocket/HTTP connections).

Pausing instead of killing

By default, an idle sandbox is killed when the idle timeout expires. If you want the sandbox to be paused instead so you can resume it later, enable the autoPause option:
When autoPause is enabled, the sandbox state transitions to paused on idle timeout. You can connect to it later to resume execution.

Combining with other metadata

The idle_timeout metadata key can be combined with other metadata keys you may already use:

Timeout constraints

If you set idle_timeout to a value below the minimum threshold (30 seconds), the idle timeout feature will be silently disabled for that sandbox. The sandbox will run until its maximum lifetime expires.

Disabling idle timeout

To explicitly disable the idle timeout for a sandbox, simply omit the idle_timeout key from the metadata, or set it to "0":

Common use cases

Short-lived execution tasks

Use a short idle timeout for sandboxes that run one-off tasks and don’t need to persist after the client disconnects:

Long-running interactive sessions

Use a longer idle timeout for sandboxes used in interactive sessions where users may step away temporarily:
Last modified on June 24, 2026