> ## Documentation Index
> Fetch the complete documentation index at: https://docs.beam.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Timeouts and Retries

Set how long tasks can run, wait in a queue, and retry.

## Execution Timeouts

| Workload | Python SDK default `timeout` | Behavior |
| - | - | - |
| `function`, `schedule`, `task_queue` | 3600 seconds | Execution budget for a task |
| `endpoint`, `asgi`, `realtime` | 180 seconds | Request execution budget; the gateway caps it at 600 seconds |

```python theme={null}
from beam import function


@function(timeout=600)
def handler():
    return sum(range(1_000_000))


if __name__ == "__main__":
    print(handler.remote())
```

Use `timeout=-1` to disable timeouts on functions and task queues. Endpoints are capped at 600 seconds, including when `timeout` is nonpositive. Use a [task queue](/v2/task-queue/running-tasks) for longer jobs.

## Pending-task Expiry

`TaskPolicy(ttl=...)` limits how long a task may remain pending. Defaults are 12 hours for functions and scheduled jobs, 2 hours for task queues, and 600 seconds for endpoints. The gateway caps an explicitly configured TTL at 24 hours.

```python theme={null}
from beam import TaskPolicy, task_queue


@task_queue(timeout=1800, task_policy=TaskPolicy(ttl=900))
def process(**inputs):
    return {"received": inputs}
```

Client and proxy timeouts apply separately.

## Retries

Functions, schedules, and task queues default to 3 retries. Configure `retries` on the decorator; the gateway caps retries at 5. Endpoint and ASGI requests have automatic task retries disabled.

A task queue can retry selected exceptions with `retry_for`:

```python theme={null}
from beam import task_queue


@task_queue(retries=2, retry_for=[ConnectionError])
def process(**inputs):
    # Raise ConnectionError for a transient dependency failure.
    return {"received": inputs}
```

Make retried tasks safe to run more than once. `retry_for` is only available on task queues.

Nonzero `TaskPolicy.timeout` and `max_retries` override the decorator; zero uses its settings. Set `retries=0` on the decorator to disable retries.

## Container Lifetime

`keep_warm_seconds` controls how long idle containers stay running. For sandboxes, it sets the [sandbox lifetime](/v2/sandbox/configuration). Neither setting is a task execution timeout.


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