# Errors

## DaytonaError

```python
class DaytonaError(Exception)
```

Base error for Daytona SDK.

**Example**:

```python
try:
    sandbox = daytona.get("missing-sandbox")
except DaytonaError as exc:
    print(exc.status_code)
    print(exc.error_code)
    print(exc.message)
```
  

**Attributes**:

- `message` _str_ - Error message
- `status_code` _int | None_ - HTTP status code if available
- `error_code` _str | None_ - Machine-readable error code if available
- `headers` _dict[str, Any]_ - Response headers

#### DaytonaError.\_\_init\_\_

```python
def __init__(message: str,
             status_code: int | None = None,
             headers: Mapping[str, Any] | None = None,
             error_code: str | None = None)
```

Initialize Daytona error.

**Arguments**:

- `message` _str_ - Error message
- `status_code` _int | None_ - HTTP status code if available
- `headers` _Mapping[str, Any] | None_ - Response headers if available
- `error_code` _str | None_ - Machine-readable error code if available


## DaytonaNotFoundError

```python
class DaytonaNotFoundError(DaytonaError)
```

Error for when a resource is not found (HTTP 404).

**Example**:

```python
try:
    sandbox.fs.download_file("/workspace/missing.txt")
except DaytonaNotFoundError as exc:
    print(exc.status_code)
```

## DaytonaAuthenticationError

```python
class DaytonaAuthenticationError(DaytonaError)
```

Error for when authentication fails (HTTP 401).

**Example**:

```python
try:
    for sandbox in daytona.list():
        print(sandbox.id)
except DaytonaAuthenticationError as exc:
    print(exc.status_code)
```

## DaytonaAuthorizationError

```python
class DaytonaAuthorizationError(DaytonaError)
```

Error for when the request is forbidden (HTTP 403).

**Example**:

```python
try:
    daytona.get("sandbox-without-access")
except DaytonaAuthorizationError as exc:
    print(exc.message)
```

## DaytonaRateLimitError

```python
class DaytonaRateLimitError(DaytonaError)
```

Error for when rate limit is exceeded (HTTP 429).

**Example**:

```python
try:
    for sandbox in daytona.list():
        print(sandbox.id)
except DaytonaRateLimitError as exc:
    print(exc.error_code)
```

## DaytonaConflictError

```python
class DaytonaConflictError(DaytonaError)
```

Error for when a resource conflict occurs (HTTP 409).

**Example**:

```python
try:
    params = CreateSandboxFromSnapshotParams(name="existing-sandbox")
    daytona.create(params)
except DaytonaConflictError as exc:
    print(exc.error_code)
```

## DaytonaValidationError

```python
class DaytonaValidationError(DaytonaError)
```

Error for when input validation fails (HTTP 400 or client-side validation).

**Example**:

```python
try:
    Image.debian_slim("3.8")
except DaytonaValidationError as exc:
    print(exc.message)
```

## DaytonaTimeoutError

```python
class DaytonaTimeoutError(DaytonaError)
```

Error for when a timeout occurs.

**Example**:

```python
try:
    sandbox.wait_for_sandbox_start(timeout=1)
except DaytonaTimeoutError as exc:
    print(exc.message)
```

## DaytonaConnectionError

```python
class DaytonaConnectionError(DaytonaError)
```

Error for when a network connection fails.

**Example**:

```python
try:
    pty_handle.wait_for_connection()
except DaytonaConnectionError as exc:
    print(exc.message)
```

#### error\_class\_from\_status\_code

```python
def error_class_from_status_code(
        status_code: int | None) -> type[DaytonaError]
```

Map an HTTP status code to the corresponding DaytonaError subclass.

#### create\_daytona\_error

```python
def create_daytona_error(message: str,
                         status_code: int | None = None,
                         headers: Mapping[str, Any] | None = None,
                         error_code: str | None = None) -> DaytonaError
```

Create the appropriate DaytonaError subclass from structured error metadata.