> ## 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.

# Run a task in a Sandbox

> Launch a temporary headless Sandbox on Pro or Max plans, run bounded Exec work, export results, and clean up before the 24-hour expiry.

A Deepest **Sandbox** is a temporary, headless Linux environment for bounded builds, tests, or isolated experiments. Sandboxes share your Account's running Memory, `shared_cpus`, Storage, and Paid network pool with Computers—and do **not** consume `persistent_computers` slots.

Every Sandbox has a fixed **24-hour hard lifetime** from creation and defaults to automatic **Stop after 30 minutes** without recognized activity. You can adjust or disable idle Stop, but nothing can extend the 24-hour hard deadline.

> [!NOTE]
>
> **Plan eligibility:** Sandboxes require `sandbox_enabled: true` (included on **Pro, Max 16, and Max 32**; **excluded on Starter**). On Starter, Sandbox requests return `SANDBOX_NOT_ENABLED` (`403`).

## When to use a Sandbox vs. Computer

* **Choose a Sandbox** when the job is headless, finishes cleanly, and exports its artifacts before the 24-hour deadline.
* **Choose a [Computer](https://docs.deepest.dev/computers/lifecycle.md)** for persistent files, SSH/SFTP/VS Code, Desktop/Chromium, Private Preview, Share links, Tools Quick Install, Snapshots, Clone, Memory Resize, or tasks over 24 hours.
* Sandboxes cannot be promoted into Computers, and Deepest provides no automatic result archive after expiry—treat exported files as untrusted until reviewed.

## Create, execute, and export results

In the Console, open **Machines → Create Machine**, select **Sandbox** and **Memory** (256 MiB steps), and click **Create and start**.

From [`@deepest/sdk`](https://docs.deepest.dev/api-and-sdk/typescript), save a unique `DEEPEST_SANDBOX_KEY` before creation, inspect `expires_at`, run your bounded task via `exec`, and export results explicitly before deleting or expiring:

```js theme={null}
import { writeFile } from "node:fs/promises";
import { Deepest } from "@deepest/sdk";

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

const pool = await deepest.resources.get();
if (!pool.ok) throw new Error(pool.error.code);
if (pool.result.entitlement.status !== "active" || !pool.result.sandbox_enabled) {
  throw new Error("Account is not eligible for Sandboxes (check plan and status).");
}

const created = await deepest.sandboxes.create({
  idempotency_key: process.env.DEEPEST_SANDBOX_KEY,
  ram_mib: 512,
});
if (!created.ok) throw new Error(`${created.error.code} (${created.retry})`);

const sandbox = deepest.sandbox(created.result.id);
console.log("Sandbox:", created.result.id, "Expires:", new Date(created.result.expires_at).toISOString());

const task = await sandbox.exec({
  command: "sh",
  args: ["-lc", "mkdir -p \"$HOME/out\"; printf 'test-result: passed\\n' > \"$HOME/out/result.txt\"; cat \"$HOME/out/result.txt\""],
  timeout_ms: 10000,
});
if (!task.ok || task.result.exit_code !== 0 || task.result.timed_out || task.result.output_truncated) {
  throw new Error("Sandbox task failed or truncated; inspect before continuing.");
}

// Export bounded text output explicitly to local caller before expiry or Delete.
await writeFile("sandbox-result.txt", task.result.stdout, { encoding: "utf8", flag: "wx" });
```

> [!WARNING]
>
> `exec` output is bounded and suitable only for small textual outputs—never rely on truncated output as a complete export. For large or binary artifacts, push explicitly from inside the Guest to your repository or authorized external artifact store and verify the upload before deleting the Sandbox.

## Stop or delete after exporting

Stopping releases running Memory while retaining the Sandbox disk only until its original `expires_at`. Once you have verified exported artifacts, explicitly delete the Sandbox and confirm `NOT_FOUND`:

```js theme={null}
const deleted = await sandbox.delete();
if (!deleted.ok) throw new Error(`${deleted.error.code} (${deleted.retry})`);
```

## Secrets, isolation, and platform boundaries

* Sandboxes start with **zero** [Vault](https://docs.deepest.dev/security/vault.md) grants—explicitly grant only narrow secrets with exact `allowed_hosts`. Never place an Account Agent Key inside an untrusted Sandbox.
* Isolation does not block outbound Internet egress by default; malicious code in a Sandbox can reach permitted public hosts.
* Sandboxes expose `create/list/get/start/stop/delete/exec/touch/idle` and `secretGrants`, and **no** Desktop, human assistance, SSH, Preview, Share, Snapshot, Clone, or Resize endpoints.

## Failure and recovery

| Symptom | Next decision |
| - | - |
| `SANDBOX_NOT_ENABLED` | Plan excludes Sandboxes (e.g. Starter); use a Computer or eligible plan |
| `ENTITLEMENT_REQUIRED` | Restore active Account entitlement (hard 24h expiry still applies) |
| `LIMIT_EXCEEDED` | Inspect `error.limit` (`memory`, `reserved_intents`, `secret_grants`) and shared pool |
| `NOT_RUNNING` / `stop_reason: "idle"` | Check `expires_at`; Start the same Sandbox only if enough time remains |
| `NOT_FOUND` after expiry | Sandbox expired and was deleted; rely on earlier exports |
| `EXEC_BUSY` / `LIFECYCLE_BUSY` (`retry: "safe"`) | Wait `error.retry_after_seconds` and retry explicitly |
| `UNKNOWN` (`retry: "query-first"`) | Query the original Sandbox and concrete task effect; preserve `DEEPEST_SANDBOX_KEY` |

Continue with [Sandbox lifecycle and idle policy](https://docs.deepest.dev/sandboxes/lifecycle.md), [Account resources](https://docs.deepest.dev/concepts/account-resources.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.