# Configure tasks

> **📝 Note**
>
> An LLM-optimized bundle of this entire section is available at [`section.md`](https://www.union.ai/docs/v2/union/user-guide/task-configuration/section.md).
> This single file contains all pages in this section, optimized for AI coding agent context.

As we saw in [**Quickstart**](https://www.union.ai/docs/v2/union/user-guide/quickstart/page.md), you can run any Python function as a task in Flyte just by decorating it with `@env.task`.

This allows you to run your Python code in a distributed manner, with each function running in its own container.
Flyte manages the spinning up of the containers, the execution of the code, and the passing of data between the tasks.

The simplest possible case is a `TaskEnvironment` with only a `name` parameter, and an `env.task` decorator, with no parameters:

```
env = flyte.TaskEnvironment(name="my_env")

@env.task
async def my_task(name:str) -> str:
    return f"Hello {name}!"
```

*Source: https://github.com/unionai/unionai-examples/blob/main/v2/user-guide/task-configuration/task_config.py*

> [!NOTE]
> Notice how the `TaskEnvironment` is assigned to the variable `env` and then that variable is
> used in the `@env.task`. This is what connects the `TaskEnvironment` to the task definition.
>
> In the following we will often use `@env.task` generically to refer to the decorator,
> but it is important to remember that it is actually a decorator attached to a specific
> `TaskEnvironment` object, and the `env` part can be any variable name you like.

This will run your task in the default container environment with default settings.

But, of course, one of the key advantages of Flyte is the ability to control the software environment, hardware environment, and other execution parameters for each task, right in your Python code.
In this section we will explore the various configuration options available for tasks in Flyte.

## Task configuration levels

Task configuration is done at three levels. From most general to most specific, they are:

* The `TaskEnvironment` level: setting parameters when defining the `TaskEnvironment` object.
* The `@env.task` decorator level: Setting parameters in the `@env.task` decorator when defining a task function.
* The task invocation level: Using the `task.override()` method when invoking task execution.

Each level has its own set of parameters, and some parameters are shared across levels.
For shared parameters, the more specific level will override the more general one.

### Example

Here is an example of how these levels work together, showing each level with all available parameters:

```
# Level 1: TaskEnvironment - Base configuration
env_2 = flyte.TaskEnvironment(
    name="data_processing_env",
    image=flyte.Image.from_debian_base(),
    resources=flyte.Resources(cpu=1, memory="512Mi"),
    env_vars={"MY_VAR": "value"},
    # secrets=flyte.Secret(key="openapi_key", as_env_var="MY_API_KEY"),
    cache="disable",
    # pod_template=my_pod_template,
    # reusable=flyte.ReusePolicy(replicas=2, idle_ttl=300),
    depends_on=[another_env],
    description="Data processing task environment",
    # plugin_config=my_plugin_config
)

# Level 2: Decorator - Override some environment settings
@env_2.task(
    short_name="process",
    # secrets=flyte.Secret(key="openapi_key", as_env_var="MY_API_KEY_2"),
    cache="auto",
    # pod_template=my_pod_template,
    report=True,
    max_inline_io_bytes=100 * 1024,
    retries=3,
    timeout=60,
    docs="This task processes data and generates a report."
)
async def process_data(data_path: str) -> str:
    return f"Processed {data_path}"

@env_2.task
async def invoke_process_data() -> str:
    result = await process_data.override(
        resources=flyte.Resources(cpu=4, memory="2Gi"),
        env_vars={"MY_VAR": "new_value"},
        # secrets=flyte.Secret(key="openapi_key", as_env_var="MY_API_KEY_3"),
        cache="auto",
        max_inline_io_bytes=100 * 1024,
        retries=3,
        timeout=60
    )("input.csv")
    return result
```

*Source: https://github.com/unionai/unionai-examples/blob/main/v2/user-guide/task-configuration/task_config.py*

## Task configuration parameters

Each parameter is documented in detail on its dedicated page in this section.
For the complete parameter interaction matrix showing which parameters can be set at which level, and for full type signatures and constraints, see the [`TaskEnvironment` API reference](https://www.union.ai/docs/v2/union/api-reference/flyte-sdk/packages/flyte/taskenvironment/page.md).

| Parameter | Set at | Details |
|-----------|--------|---------|
| **name** | `TaskEnvironment` only | [Additional task settings](https://www.union.ai/docs/v2/union/user-guide/task-configuration/additional-task-settings/page.md) &bull; [`TaskEnvironment` API ref](https://www.union.ai/docs/v2/union/api-reference/flyte-sdk/packages/flyte/taskenvironment/page.md) |
| **image** | `TaskEnvironment` only | [Container images](https://www.union.ai/docs/v2/union/user-guide/task-configuration/container-images/page.md) &bull; [`Image` API ref](https://www.union.ai/docs/v2/union/api-reference/flyte-sdk/packages/flyte/image/page.md) |
| **depends_on** | `TaskEnvironment` only | [Multiple environments](https://www.union.ai/docs/v2/union/user-guide/task-configuration/multiple-environments/page.md) |
| **description** | `TaskEnvironment` only | [Additional task settings](https://www.union.ai/docs/v2/union/user-guide/task-configuration/additional-task-settings/page.md) |
| **plugin_config** | `TaskEnvironment` only | [Task plugins](https://www.union.ai/docs/v2/union/user-guide/task-configuration/task-plugins/page.md) |
| **resources** | `TaskEnvironment`, `override`\* | [Resources](https://www.union.ai/docs/v2/union/user-guide/task-configuration/resources/page.md) &bull; [`Resources` API ref](https://www.union.ai/docs/v2/union/api-reference/flyte-sdk/packages/flyte/resources/page.md) |
| **env_vars** | `TaskEnvironment`, `override`\* | [Additional task settings](https://www.union.ai/docs/v2/union/user-guide/task-configuration/additional-task-settings/page.md#environment-variables) |
| **secrets** | `TaskEnvironment`, `override`\* | [Secrets](https://www.union.ai/docs/v2/union/user-guide/task-configuration/secrets/page.md) &bull; [`Secret` API ref](https://www.union.ai/docs/v2/union/api-reference/flyte-sdk/packages/flyte/secret/page.md) |
| **cache** | All three levels | [Caching](https://www.union.ai/docs/v2/union/user-guide/task-configuration/caching/page.md) &bull; [`Cache` API ref](https://www.union.ai/docs/v2/union/api-reference/flyte-sdk/packages/flyte/cache/page.md) |
| **pod_template** | All three levels | [Pod templates](https://www.union.ai/docs/v2/union/user-guide/task-configuration/pod-templates/page.md) &bull; [`PodTemplate` API ref](https://www.union.ai/docs/v2/union/api-reference/flyte-sdk/packages/flyte/podtemplate/page.md) |
| **reusable** | `TaskEnvironment`, `override` | [Reusable containers](https://www.union.ai/docs/v2/union/user-guide/task-configuration/reusable-containers/page.md) &bull; [`ReusePolicy` API ref](https://www.union.ai/docs/v2/union/api-reference/flyte-sdk/packages/flyte/reusepolicy/page.md) |
| **interruptible** | All three levels | [Interruptible tasks and queues](https://www.union.ai/docs/v2/union/user-guide/task-configuration/interruptible-tasks-and-queues/page.md) |
| **queue** | All three levels | [Interruptible tasks and queues](https://www.union.ai/docs/v2/union/user-guide/task-configuration/interruptible-tasks-and-queues/page.md) |
| **short_name** | `@env.task`, `override` | [Additional task settings](https://www.union.ai/docs/v2/union/user-guide/task-configuration/additional-task-settings/page.md) |
| **retries** | `@env.task`, `override` | [Retries and timeouts](https://www.union.ai/docs/v2/union/user-guide/task-configuration/retries-and-timeouts/page.md) &bull; [`RetryStrategy` API ref](https://www.union.ai/docs/v2/union/api-reference/flyte-sdk/packages/flyte/retrystrategy/page.md) |
| **timeout** | `@env.task`, `override` | [Retries and timeouts](https://www.union.ai/docs/v2/union/user-guide/task-configuration/retries-and-timeouts/page.md) &bull; [`Timeout` API ref](https://www.union.ai/docs/v2/union/api-reference/flyte-sdk/packages/flyte/timeout/page.md) |
| **max_inline_io_bytes** | `@env.task`, `override` | [Additional task settings](https://www.union.ai/docs/v2/union/user-guide/task-configuration/additional-task-settings/page.md#inline-io-threshold) |
| **links** | `@env.task`, `override` | [Additional task settings](https://www.union.ai/docs/v2/union/user-guide/task-configuration/additional-task-settings/page.md#links) |
| **report** | `@env.task` only | [Additional task settings](https://www.union.ai/docs/v2/union/user-guide/task-configuration/additional-task-settings/page.md#report) |
| **triggers** | `@env.task` only | [Triggers](https://www.union.ai/docs/v2/union/user-guide/task-configuration/triggers/page.md) &bull; [`Trigger` API ref](https://www.union.ai/docs/v2/union/api-reference/flyte-sdk/packages/flyte/trigger/page.md) |
| **docs** | `@env.task` only | [Additional task settings](https://www.union.ai/docs/v2/union/user-guide/task-configuration/additional-task-settings/page.md#docs) |

\*When `reusable` is set, `resources`, `env_vars`, and `secrets` can only be overridden via `task.override()` with `reusable="off"` in the same call.

## Subpages

- [Container images](https://www.union.ai/docs/v2/union/user-guide/task-configuration/container-images/page.md)
  - Specifying your own image directly
  - Specifying your own image with the `flyte.Image` object
  - Example: Defining a custom image with `Image.from_debian_base`
  - Example: Defining an image based on uv script metadata
  - Image building
  - Configuring the `builder`
  - Local image building
  - Remote `ImageBuilder`
  - Install private PyPI packages
- [Resources](https://www.union.ai/docs/v2/union/user-guide/task-configuration/resources/page.md)
  - Resources data class
  - Examples
  - Usage in TaskEnvironment
  - Usage in a task-specific override
- [Secrets](https://www.union.ai/docs/v2/union/user-guide/task-configuration/secrets/page.md)
  - Creating a literal string secret
  - Creating a file secret
  - Scoping secrets
  - Listing secrets
  - Deleting secrets
  - Using a literal string secret
  - Using a file secret
- [Caching](https://www.union.ai/docs/v2/union/user-guide/task-configuration/caching/page.md)
  - Overview
  - Basic caching usage
  - `"auto"` - Automatic versioning
  - `"override"`
  - `"disable"` - No caching
  - Advanced caching configuration
  - Ignoring specific inputs
  - Cache serialization
  - Salt for cache key variation
  - Cache policies
  - Function body policy (default)
  - Custom cache policies
  - Caching configuration at different levels
  - `TaskEnvironment` Level
  - `@env.task` decorator level
  - `task.override` level
  - Runtime cache control
  - Project and domain cache isolation
  - Local development caching
- [Reusable containers](https://www.union.ai/docs/v2/union/user-guide/task-configuration/reusable-containers/page.md)
  - How It Works
  - Basic Usage
  - `ReusePolicy` parameters
  - Understanding parameter relationships
  - Key relationships
  - Simple example
- [Pod templates](https://www.union.ai/docs/v2/union/user-guide/task-configuration/pod-templates/page.md)
  - How it works
  - Requirements
  - Basic usage
  - PodTemplate parameters
  - Volume mounts
  - GCS/S3 volume mounts
  - Sidecar containers
  - Image pull secrets
  - Cluster-specific configuration
  - Important notes
  - Best practices
  - Learn more
- [Multiple environments](https://www.union.ai/docs/v2/union/user-guide/task-configuration/multiple-environments/page.md)
  - Constraints on multiple environments
  - Task `depends_on` constraints
  - Dependency inclusion constraints
  - Example
- [Retries and timeouts](https://www.union.ai/docs/v2/union/user-guide/task-configuration/retries-and-timeouts/page.md)
  - Retries
  - Retry example
  - Timeouts
  - Timeout example
- [Triggers](https://www.union.ai/docs/v2/union/user-guide/task-configuration/triggers/page.md)
  - Triggers are set in the task decorator
  - `flyte.Trigger`
  - The `automation` parameter with `flyte.FixedRate`
  - Examples
  - The `automation` parameter with `flyte.Cron`
  - Examples
  - The `inputs` parameter
  - Basic Usage
  - Using `flyte.TriggerTime`
  - Required vs optional parameters
  - Complex input types
  - Predefined schedule triggers
  - Available Predefined Triggers
  - Trigger time in predefined triggers
  - Multiple triggers per task
  - Deploying a task with triggers
  - Activating and deactivating triggers
  - Trigger run timing
  - Cron-based triggers
  - Fixed-rate triggers without `start_time`
  - Fixed-rate triggers with `start_time`
  - Deleting triggers
  - Schedule time zones
  - Setting time zone for a Cron schedule
  - `flyte.TriggerTime` is always in UTC
  - Daylight Savings Time behavior
- [Interruptible tasks and queues](https://www.union.ai/docs/v2/union/user-guide/task-configuration/interruptible-tasks-and-queues/page.md)
  - Interruptible tasks
  - Setting at different levels
  - Behavior on preemption
  - Queues
  - Setting at different levels
- [Task plugins](https://www.union.ai/docs/v2/union/user-guide/task-configuration/task-plugins/page.md)
  - Default Execution: Containers
  - Compute Plugins
  - Available Compute Plugins
  - How Compute Plugins Work
  - Using Compute Plugins
  - Using Plugins on Union
  - Backend Integrations
  - Next Steps
- [Additional task settings](https://www.union.ai/docs/v2/union/user-guide/task-configuration/additional-task-settings/page.md)
  - Naming and metadata
  - `name`
  - `short_name`
  - `description`
  - `docs`
  - `report`
  - `links`
  - Default inputs
  - Environment variables
  - Inline I/O threshold

---
**Source**: https://github.com/unionai/unionai-docs/blob/main/content/user-guide/task-configuration/_index.md
**HTML**: https://www.union.ai/docs/v2/union/user-guide/task-configuration/
