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

# Python Sandbox SDK errors

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

All SDK errors inherit from `SandboxError`.

```python theme={null}
from porter_sandbox import (
    AuthenticationError,
    NotFoundError,
    RateLimitError,
    SandboxError,
    SandboxTimeoutError,
    ServerError,
)
```

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

| Attribute     | Type             | Description                           |
| ------------- | ---------------- | ------------------------------------- |
| `message`     | `str`            | Human-readable error message.         |
| `status_code` | `int \| None`    | HTTP status code, when available.     |
| `body`        | `object \| None` | Parsed response body, when available. |

## Handle errors

```python theme={null}
from porter_sandbox import Porter, SandboxError

with Porter() as porter:
    sandbox = porter.sandboxes.create(image="python:3.12-slim")

    try:
        result = sandbox.exec(["python", "-c", "raise SystemExit(2)"])
        if result.exit_code != 0:
            print(result.stderr)
    except SandboxError as exc:
        print(f"Sandbox API error: {exc.message}")
    finally:
        sandbox.terminate()
```

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