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

# Manage Sandbox expiry and idle Stop

> Read the fixed 24-hour hard deadline, configure or disable idle auto-stop, refresh activity with Touch, and resume before expiry.

Every Sandbox has two independent clocks:

1. **Hard expiry (`expires_at`):** Fixed at **creation + 24 hours** (Unix milliseconds). **Nothing**—not `Start`, `Stop`, `touch()`, foreground `exec()`, or disabling idle auto-stop—can extend `expires_at`.
2. **Idle auto-stop (`idle_timeout_seconds`):** Defaults to **1,800 seconds (30 minutes)** without recognized activity. Stopping saves running Memory while preserving the Sandbox disk until `expires_at`.

## Lifecycle outcomes

| Event | Running processes | Disk & identity | Can Start again? |
| - | - | - | - |
| User Stop (`stop_reason: "user"`) | Ended | Retained until original `expires_at` | Yes, before expiry with active eligibility |
| Idle Stop (`stop_reason: "idle"`) | Ended | Retained until original `expires_at` | Yes, before expiry with active eligibility |
| Entitlement ends (`stop_reason: "entitlement"`) | Stopped | Keeps fixed 24h `expires_at` (no 30-day retention) | Only if entitlement returns before `expires_at` |
| Hard expiry (24h reached) | Stopped if running | **Deleted permanently** | No |
| Explicit Delete | Stopped if running | **Deleted permanently** | No |

## Read current policy and remaining time

```js theme={null}
import { Deepest } from "@deepest/sdk";

const deepest = new Deepest({
  baseUrl: process.env.DEEPEST_API_URL,
  apiKey: process.env.DEEPEST_API_KEY,
});
const sandbox = deepest.sandbox(process.env.DEEPEST_SANDBOX_ID);

const current = await sandbox.get();
if (!current.ok) throw new Error(`${current.error.code} (${current.retry})`);

console.log({
  id: current.result.id,
  state: current.result.state,
  expiresAt: new Date(current.result.expires_at).toISOString(),
  approxRemainingSec: Math.max(0, Math.floor((current.result.expires_at - Date.now()) / 1000)),
  idleTimeoutSeconds: current.result.idle_timeout_seconds, // omitted => idle Stop disabled
  stopReason: current.result.stop_reason, // none | user | idle | entitlement
});
```

## Recognized activity vs. background processes

* **Counts as activity:** A foreground `exec` call (while running), an explicit `sandbox.touch()` call, and changing idle policy via `sandbox.idle.set(...)`.
* **Does NOT count as activity:** Background CPU usage, daemons, detached background jobs, or network traffic alone. A background build can be idle-stopped unless idle timeout is raised or disabled.

> [!WARNING]
>
> Do not rely on an unbounded `touch()` loop instead of configuring an appropriate idle policy—and remember that even with idle Stop disabled or foreground Exec running, **hard expiry at `expires_at` still terminates and deletes the Sandbox**.

## Configure or disable idle auto-stop

In the Console, open **Settings → Stop when idle** (**30 minutes**, **60 minutes**, or **Never**) or click **I'm still using it** (`touch()`).

Through the SDK, `idle_timeout_seconds` accepts **60 through 86,400 seconds**, or omit the field (`{}`) to disable idle auto-stop:

> [tab] Set timeout (e.g., 1 hour)
>
> ```js theme={null}
> const updated = await sandbox.idle.set({ idle_timeout_seconds: 3600 });
> if (!updated.ok) throw new Error(updated.error.code);
> ```

> [tab] Disable idle auto-stop
>
> Pass an empty object `{}`—never `null` or `0`:
>
> ```js theme={null}
> const disabled = await sandbox.idle.set({});
> if (!disabled.ok || disabled.result.idle_timeout_seconds !== undefined) {
>   throw new Error("Idle auto-stop disable not confirmed.");
> }
> ```

> [tab] Refresh activity (Touch)
>
> ```js theme={null}
> const touched = await sandbox.touch();
> if (!touched.ok) throw new Error(touched.error.code);
> ```
>
> `touch()` never starts a stopped Sandbox and never moves `expires_at`.

## Resume after idle Stop

If `state === "stopped"` and enough time remains before `expires_at`, call `sandbox.start()` explicitly. Like Computers, Start is a **cold boot** on the same disk—old process IDs and TCP sockets do not resume, and current Account entitlement + running Memory must still admit it.

## Diagnose Sandbox lifecycle issues

| Observation | Meaning & next step |
| - | - |
| Stopped with `stop_reason: "idle"` | No recognized activity within idle window; Start if unexpired and raise/disable `idle.set` for background jobs |
| Stopped with `stop_reason: "entitlement"` | Account eligibility ended; restoring eligibility does not extend `expires_at` |
| `NOT_FOUND` near/after deadline | 24h TTL expired and deleted the Sandbox; use earlier exports |
| `INVALID_REQUEST` on `idle.set` | Use `60`–`86400` seconds, or `{}` to disable |
| `EXEC_BUSY` / `LIFECYCLE_BUSY` (`retry: "safe"`) | Wait `error.retry_after_seconds` and retry explicitly (a rejected `EXEC_BUSY` call does not refresh idle activity) |
| `UNKNOWN` (`retry: "query-first"`) | Query `sandbox.get()` and actual task output before mutating again |

Always budget time to export artifacts before `expires_at`, and choose a [Computer](https://docs.deepest.dev/computers/lifecycle.md) whenever work needs more than 24 hours or persistent retention. See [Sandbox overview](https://docs.deepest.dev/sandboxes/overview.md) and [Errors](https://docs.deepest.dev/api-and-sdk/errors.md).


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