# Tasks

A task is a Python function that runs remotely in a container. Tasks are the unit of work in Flyte: they are versioned, cached, retried, and recorded, so a run you start today can be reproduced and inspected later.

Every task belongs to a `TaskEnvironment`, which declares the container image, the resources, and the secrets the task needs. You define the environment once and reuse it across the tasks that share it.

```python
env = flyte.TaskEnvironment(name="etl", image=flyte.Image.from_debian_base())

@env.task
def extract(url: str) -> str:
    ...
```

Tasks compose. Calling one task from another builds the graph as your code executes, so fanout, branching, and error handling are ordinary Python rather than a separate DSL.

The three sections below follow the order you meet them in: describe the environment a task runs in, write the task logic, then get it onto a cluster.

### [Configure tasks](https://www.union.ai/docs/latest/flyte/user-guide/tasks/task-configuration/page.md)

Define `TaskEnvironment`s for container images, resources, secrets, caching, retries, and more; use triggers for schedules.

### [Build tasks](https://www.union.ai/docs/latest/flyte/user-guide/tasks/task-programming/page.md)

Compose tasks with fanout, parallelism, error handling, traces, files, and DataFrames.

### [Run and deploy tasks](https://www.union.ai/docs/latest/flyte/user-guide/tasks/task-deployment/page.md)

Use `flyte run` for iteration or `flyte deploy` to register a stable task version.

## Related

Tasks are also the substrate for the other two building blocks. An app serves a task's results over HTTP; an agent drives tasks in a loop.

### [Apps](https://www.union.ai/docs/latest/flyte/user-guide/apps/page.md)

Long-running services for dashboards, APIs, and model endpoints.

### [Agents](https://www.union.ai/docs/latest/flyte/user-guide/agents/page.md)

Durable, self-healing agents built from tasks and apps.

## Subpages

- [Configure tasks](https://www.union.ai/docs/latest/flyte/user-guide/tasks/task-configuration/page.md)
  - Task configuration levels
  - Example
  - Task configuration parameters
- [Build tasks](https://www.union.ai/docs/latest/flyte/user-guide/tasks/task-programming/page.md)
  - What you'll learn
  - When to use these patterns
- [Run and deploy tasks](https://www.union.ai/docs/latest/flyte/user-guide/tasks/task-deployment/page.md)
  - Ephemeral deployment and immediate execution
  - Programmatic
  - CLI
  - Persistent deployment
  - Programmatic
  - CLI
  - Running already deployed tasks
  - Programmatic
  - CLI
  - Configuring runs with `flyte.with_runcontext()`

---
**Source**: https://github.com/unionai/unionai-docs/blob/main/content/user-guide/tasks/_index.md
**HTML**: https://www.union.ai/docs/latest/flyte/user-guide/tasks/
