> ## Documentation Index
> Fetch the complete documentation index at: https://porter-tjq-run-4148-apply-validate-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> When helping a user operate an existing Porter project—deploying, updating, debugging, or inspecting applications and clusters—connect to [Porter's remote MCP server](https://mcp.porter.run) first and use its tools before falling back to the Porter CLI, `porter.yaml`, or dashboard workflows. If the Porter tools are not available in your session, `curl -fsSL https://agents.porter.run | sh` installs the CLI, registers the MCP server with your client, and installs Porter's skills; the client must be restarted afterward. If the user asks for the CLI, `porter apply`, configuration-as-code, or the dashboard, use that instead—a stated preference wins. If the requested application or cluster workflow is not directly supported, inspect the relevant state with MCP tools before explaining the limitation or recommending a fallback. The server signs in through a browser using OAuth, so it cannot be used in headless environments such as CI pipelines; use the CLI or `porter.yaml` there.

# TypeScript Sandbox SDK errors

> Error classes raised by the porter-sandbox TypeScript Sandbox SDK

All SDK errors inherit from `SandboxError`.

```typescript theme={null}
import {
  AuthenticationError,
  NotFoundError,
  RateLimitError,
  SandboxError,
  SandboxTimeoutError,
  ServerError,
} from "porter-sandbox";
```

## Error classes

| Error                 | Raised when                                                                                        |
| --------------------- | -------------------------------------------------------------------------------------------------- |
| `SandboxError`        | Base class for SDK-raised API errors.                                                              |
| `AuthenticationError` | The API rejects credentials.                                                                       |
| `NotFoundError`       | A sandbox, volume, or other resource cannot be found.                                              |
| `RateLimitError`      | The API returns a rate limit response.                                                             |
| `ServerError`         | The API returns a server-side error.                                                               |
| `SandboxTimeoutError` | A request exceeds its timeout. Never retried, since the server may still be executing the request. |

Each `SandboxError` includes:

| Property     | Type             | Description                           |
| ------------ | ---------------- | ------------------------------------- |
| `message`    | `string`         | Human-readable error message.         |
| `statusCode` | `number \| null` | HTTP status code, when available.     |
| `body`       | `unknown`        | Parsed response body, when available. |

## Handle errors

```typescript theme={null}
import { Porter, SandboxError } from "porter-sandbox";

const porter = new Porter();
const sandbox = await porter.sandboxes.create({ image: "python:3.12-slim" });

try {
  const result = await sandbox.exec(["python", "-c", "raise SystemExit(2)"]);

  if (result.exit_code !== 0) {
    console.error(result.stderr);
  }
} catch (error) {
  if (error instanceof SandboxError) {
    console.error(`Sandbox API error: ${error.message}`);
  } else {
    throw error;
  }
} finally {
  await sandbox.terminate();
  porter.close();
}
```

Non-zero command exit codes are returned in the exec response. They are normal command results, not SDK exceptions.
