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

# Use Deepest from an Agent or program

> Check Account resources, reuse or create a Computer, execute verified commands, and recover cleanly without duplicating side effects.

An Agent or automation script operates Deepest through Public API V1 or the `@deepest/sdk` TypeScript SDK using an **Agent API Key**. It acts on the exact same Account, Computers, Sandboxes, and resource pool as the Web Console.

> [!WARNING]
>
> **Protect your Agent API Key:** An Agent API Key is a strong **account-wide** credential. Keep it in the trusted caller's secret store—never embed it in prompts, source repositories, Guest files, runtime links, or untrusted tool output.

## Prepare the caller

**1. Create an Agent API Key in the Console**

The human account owner signs in to the Console, redeems an active Beta Invite if needed ([Access and retention](https://docs.deepest.dev/account/access-and-retention.md)), and creates a key under [Agent Keys](https://docs.deepest.dev/account/agent-keys.md).

**2. Install the TypeScript SDK**

Install `@deepest/sdk` (`0.1.0`, MIT) in an ESM project running **Node.js 18 or later**:

```sh theme={null}
npm install @deepest/sdk
```

**3. Set trusted caller environment variables**

Pass `DEEPEST_API_URL` (your control API origin, e.g. `https://console.deepest.dev`, without `/v1`) and `DEEPEST_API_KEY` from the caller's environment. `https://deepest.dev` is the public website, not the Control API—always send Agent API Keys only to your configured control origin (`https://console.deepest.dev` for hosted Deepest), and never use a Preview, Share, or Viewer runtime URL as `baseUrl`.

## Reuse an existing workspace before creating another

Before creating a new Machine, inspect Account resources and existing Computers:

1. **Read `resources.get()`** to verify `entitlement.status === "active"`, sufficient Memory (`ram_limit_mib - ram_used_mib`), `storage_status`, and `machine_count_constraints` (`persistent_computers`).
2. **List Computers (`computers.list()`)** and match by stable Computer ID (`id`)—display names are human labels, not unique identifiers, and renaming a Computer does not change its ID.
3. **Reuse** the existing Computer when it already holds the target repository, environment, or authorized session.
4. **Create a new Computer** only when the task needs a separate persistent workspace. Use a [Sandbox](https://docs.deepest.dev/sandboxes/overview.md) for an eligible temporary headless task (Pro or Max plans; disabled on Starter) that can finish and export results within 24 hours.

Deepest does not automatically select a Machine, migrate projects, or prioritize one Computer over others.

## Run a verified task

Choose whether your Agent is connecting to an existing Computer or creating a new one with a saved `idempotency_key`:

> [tab] Create a Computer
>
> Save one unique `DEEPEST_CREATE_KEY` alongside your intended `ram_mib` before calling `computers.create()`. Reusing that identical key and Memory request lets you recover cleanly if the network drops; generating a random key per retry creates duplicate Computers.
>
> ```js theme={null}
> // Save as create-and-run.mjs (Node.js 18+ ESM)
> 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") {
>   throw new Error("Account entitlement is not active.");
> }
>
> // Check Memory, Storage, and persistent Computer count limits (advisory preflight)
> const ram_mib = 512;
> const freeRam = pool.result.ram_limit_mib - pool.result.ram_used_mib;
> const countLimit = pool.result.machine_count_constraints.find(
>   (c) => c.kind === "computer" && c.scope === "retained"
> );
> if (freeRam < ram_mib || pool.result.storage_status === "over_limit" ||
>     (countLimit && countLimit.used !== undefined && countLimit.used >= countLimit.limit)) {
>   throw new Error("Insufficient Account pool capacity or Computer slots.");
> }
>
> const created = await deepest.computers.create({
>   idempotency_key: process.env.DEEPEST_CREATE_KEY,
>   ram_mib,
> });
> if (!created.ok) throw new Error(`${created.error.code} (${created.retry})`);
> if (created.result.state !== "running") {
>   throw new Error(`Query Computer ${created.result.id} before executing.`);
> }
>
> const exec = await deepest.computer(created.result.id).exec({
>   command: "python3",
>   args: ["-c", "import json; print(json.dumps({'sum': sum([2, 3, 5, 7])}))"],
>   timeout_ms: 5000,
> });
> if (!exec.ok) throw new Error(`${exec.error.code} (${exec.retry})`);
> if (exec.result.timed_out || exec.result.output_truncated || exec.result.exit_code !== 0) {
>   throw new Error("Command did not complete cleanly; inspect result.");
> }
> console.log("Computer:", created.result.id, "Output:", JSON.parse(exec.result.stdout));
> ```

> [tab] Reuse an existing Computer
>
> When `DEEPEST_COMPUTER_ID` already holds your repository or environment, inspect its state, start it only if `stopped`, and run the bounded command:
>
> ```js theme={null}
> // Save as reuse-and-run.mjs (Node.js 18+ ESM)
> import { Deepest } from "@deepest/sdk";
>
> const deepest = new Deepest({
>   baseUrl: process.env.DEEPEST_API_URL,
>   apiKey: process.env.DEEPEST_API_KEY,
> });
> const computer = deepest.computer(process.env.DEEPEST_COMPUTER_ID);
>
> let current = await computer.get();
> if (!current.ok) throw new Error(`${current.error.code} (${current.retry})`);
> if (current.result.state === "stopped") {
>   current = await computer.start();
>   if (!current.ok) throw new Error(`${current.error.code} (${current.retry})`);
> }
> if (current.result.state !== "running") {
>   throw new Error(`Computer state is ${current.result.state}; observe before acting.`);
> }
>
> const exec = await computer.exec({
>   command: "python3",
>   args: ["-c", "import json; print(json.dumps({'sum': sum([2, 3, 5, 7])}))"],
>   timeout_ms: 5000,
> });
> if (!exec.ok) throw new Error(`${exec.error.code} (${exec.retry})`);
> if (exec.result.timed_out || exec.result.output_truncated || exec.result.exit_code !== 0) {
>   throw new Error("Command did not complete cleanly; inspect result.");
> }
> console.log("Computer:", current.result.id, "Output:", JSON.parse(exec.result.stdout));
> ```

> [!NOTE]
>
> Preflight checks against `resources.get()` are advisory—another authorized actor or platform capacity check may still change admission between reading resources and submitting Create or Start. The server's response is authoritative.

## Verify and finish cleanly

* **Verify actual task outcomes:** A `running` Computer proves lifecycle only—not that a build succeeded, a file was written, or a remote deployment finished. For file-changing commands, inspect the target file or status explicitly.
* **Check entitlement margin:** Before starting long work, verify `pool.result.entitlement.expires_at` (Unix milliseconds when present) covers the planned duration.
* **Inspect Exec fields:** Even when `exec.ok` is `true`, inspect `exit_code`, `timed_out`, and `output_truncated`.
* **Stop when idle:** Persistent Computers have no automatic idle Stop. When finished and no service needs to keep running, explicitly Stop the Computer to release running Memory while preserving its disk:

```js theme={null}
// Run only after confirming no ongoing workload needs this Computer running.
const stopped = await deepest.computer(computerId).stop();
if (!stopped.ok) throw new Error(`${stopped.error.code} (${stopped.retry})`);
console.log(stopped.result.id, stopped.result.state);
```

> [!TIP]
>
> Stop frees running Memory and keeps the disk. Only call `delete()` when the user explicitly wants to destroy the Computer and attached snapshots (and release its `persistent_computers` count slot).

## Defensive recovery & failure decisions

The SDK never retries automatically. Branch on `error.code`, `retry`, and structured fields—never prose in `error.message`:

| Failure / Signal | Meaning & Safe Agent Action |
| - | - |
| `UNKNOWN` (`retry: "query-first"`) | Physical outcome is uncertain (HTTP 502 or SDK transport/parse failure). Keep the original `resource_id`, target ID, and `idempotency_key`; query the original object or concrete task effect before any mutation. Never invent a replacement Computer. |
| `EXEC_BUSY` / `LIFECYCLE_BUSY` (HTTP 429, `retry: "safe"`) | Refused **before dispatch** due to shared Account contention. Wait at least `error.retry_after_seconds` (equal to `Retry-After`) and retry only the refused operation with the same inputs and original `idempotency_key` where applicable. |
| `LIMIT_EXCEEDED` (HTTP 409, `retry: "no-retry"`) | Inspect `error.limit.dimension` and `scope`: `memory`, `persistent_computers` (stopped Computers still count until Delete), `reserved_intents`, `share_records`, or `secret_grants`. Do not assume every limit is Memory. |
| `ENTITLEMENT_REQUIRED` (HTTP 403) | Re-read `resources.get()` (check `none` or `retention` deadline) and ask the human owner to restore entitlement; a new Agent Key will not fix this. |
| `SANDBOX_NOT_ENABLED` (HTTP 403) | Account lacks Sandbox entitlement (for example on Starter). Use a Computer or request an eligible plan. |
| Nonzero `exit_code` (`ok: true`) | API delivery succeeded (`no-retry`), while the guest command returned failure. Inspect `stdout`/`stderr` and fix the command instead of replaying prior mutations. |

See [Errors](https://docs.deepest.dev/api-and-sdk/errors.md) and [Reliability and recovery](https://docs.deepest.dev/api-and-sdk/reliability.md) for the full operation recovery matrix.

## Human boundaries and optional tooling

* **Human-only operations:** An Agent API Key cannot manage Agent Keys (`agentKeys.list`, `agentKeys.create`, `agentKeys.revoke`), redeem invitations (`invites.redeem`), or emit human-assistance control signals (`assistance.begin`, `assistance.touch`, `assistance.complete`). Request help with `computer(id).assistance.request()`, deliver the returned `dashboard_url` to the human, wait while state is `waiting_human` or `human_active`, and re-observe the application after control returns to `agent`. See [Human assistance](https://docs.deepest.dev/desktop/human-assistance.md).
* **No public CLI or MCP server:** Deepest does not distribute an official CLI or MCP server. Operate via standard SSH, the HTTP API, or `@deepest/sdk`. Do not invent package names or commands.
* **No platform browser-control API:** Desktop provides visual access and human-handoff coordination on Computers, **not** screenshot, pixel-click, DOM, CDP, or Playwright APIs. User-managed browser automation tools installed inside the Guest remain ordinary Guest commands.
* **Exact schemas:** Use the [API Reference](https://docs.deepest.dev/api-reference.md) (`GET /openapi.json`) for exact parameters, schemas, and auth scopes.


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