* This page is part of the Union.ai v2 docs.
* Full index: https://www.union.ai/docs/v2/union/llms.txt
* Union.ai is a commercial superset of the open-source Flyte project and uses the same `flyte` SDK and CLI, so questions about Flyte are usually answered here too.
* Only refer to the open-source Flyte docs if you are explicitly looking for information about the open-source Flyte project, particularly the open-source Flyte backend. The open-source Flyte v2 docs are at https://www.union.ai/docs/v2/flyte/llms.txt
* These are the v2 docs. v1 is out of date and deprecated. Only refer to v1 docs if asked explicitly about v1. The v1 index is at https://www.union.ai/docs/v1/union/llms.txt

Run tasks and apps directly in your local Python process with no Kubernetes cluster or Docker required. Ideal for rapid iteration and debugging.

# Run locally in Python

Flyte runs locally with no cluster or Docker needed. Install the SDK, write tasks, and run them on your machine. When you're ready to scale, drop the `--local` flag and the same code runs on-cluster, on whichever cluster your configuration points at.

> [!INFO] Try it in your browser
> Follow along with this guide in Google Colab without installing anything locally.
>
> [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/unionai/unionai-examples/blob/main/v2/user-guide/getting-started/ten_minutes_to_flyte.ipynb)

## Getting started

If you haven't already, install the SDK and configure local persistence as described in the [Quickstart](https://www.union.ai/docs/v2/union/user-guide/get-started/quickstart.md).

## Running tasks locally

The `--local` flag tells Flyte to execute a task in your local Python environment rather than on-cluster. Add `--tui` to launch the interactive Terminal UI for real-time monitoring.

Basic local execution:

```bash
flyte run --local hello.py main
```

With the interactive TUI:

```bash
flyte run --local --tui hello.py main
```

You can also run tasks programmatically using the Python SDK with `flyte.run()`. See [Run and deploy tasks](https://www.union.ai/docs/v2/union/user-guide/tasks/task-deployment.md) for details.

## Two ways to run a task

There are two distinct ways to run a task, and it's easy to confuse them when you're new. They differ in *who* calls `flyte.run()`.

### As a script: `python hello.py`

You call `flyte.run()` yourself, from inside an `if __name__ == "__main__":` block, and execute the file with plain Python:

```python
# hello.py
import flyte

env = flyte.TaskEnvironment(name="hello_env")

@env.task
def main(x_list: list[int] = list(range(10))) -> float:
    return sum(x_list) / len(x_list)

if __name__ == "__main__":
    flyte.init_from_config()       # load your local config (.flyte/config.yaml)
    run = flyte.run(main)          # call the task; pass inputs as keyword args
    print(run.name)
    run.wait()
```

Then run the file as an ordinary Python script:

```bash
python hello.py
```

Because *your code* decides which task runs and with what inputs, you pass inputs directly as arguments to `flyte.run()`, for example `flyte.run(main, x_list=[1, 2, 3])`. Use `flyte.run.aio(...)` from within async code.

### Via the CLI: `flyte run`

The `flyte run` CLI does the calling for you. You don't need a `__main__` block; instead you name the file and the task on the command line, and the CLI invokes it:

```bash
flyte run --local hello.py main
```

The task's **parameters become CLI options**. Each task input maps to a `--<name>` flag (run `flyte run --local hello.py main --help` to see them, with their defaults). For example, to override `x_list`:

```bash
flyte run --local hello.py main --x_list '[1, 2, 3]'
```

> [!NOTE]
> A common first-run trip-up: invoking `flyte run` against a task whose inputs have **no defaults** without supplying them. The CLI stops before running the task and names each missing input with its type, for example `Missing required parameter(s): --x (type: INTEGER)`. (`bool` inputs default to `False` and `Optional` inputs to `None`, so they are never reported missing.) If you hit this, check `--help` and pass the required `--<name>` values (or give the parameters defaults in the task signature, as `main` does above).

## Terminal UI

The TUI is an interactive split-screen dashboard. Task tree on the left, details and logs on the right.

```bash
flyte run --local --tui hello.py main
```

![TUI agent run](https://www.union.ai/docs/v2/union/_static/images/user-guide/quickstart/run-tui.png)

What you see:

- **Task tree** with live status: `●` running, `✓` done, `✗` failed
- **Cache indicators**: `$` cache hit, `~` cache enabled but missed
- **Live logs**: `print()` output streams in real time
- **Details panel**: inputs, outputs, timing, report paths
- **Traced sub-tasks**: child nodes for `@flyte.trace` decorated functions

**Keyboard shortcuts:**

| Key | Action |
|-----|--------|
| `q` | Quit |
| `d` | Details tab |
| `l` | Logs tab |

### Exploring past runs

If you created a config file via `flyte create config --local-persistence`, Flyte
persists the inputs and outputs of every task run locally, so you can always go back and inspect what a task received and produced. Launch the TUI on its own to browse past runs, compare inputs and outputs, and review reports:

```bash
flyte start tui
```

## Track local runs in the console

A local run normally leaves no trace on the control plane. Add `--tracked` and the run still executes on your machine, but its progress is reported to Union.ai so you can watch it in the console:

```bash
flyte run --tracked hello.py main
```

Tracked runs appear in the console under **Tracked Runs**, which is its own section in the project sidebar. They are not listed under **Runs**, which shows runs the platform executed for you.

The command prints a link to the run when it starts. Tracking covers the run's actions and attempts, their phases, and their inputs, outputs, reports and cache status. Logs are not reported, so `print()` output stays in your terminal.

Reporting never gets in the way of the run itself: if the control plane is unreachable, the failure is logged and your local run finishes normally.

You can abort a tracked run from the console, but this cannot stop the process running on your machine. Per-organization limits apply to tracked runs: concurrent runs and actions, actions per run, and run creations per month.

If you do not have a workflow to hand yet, `hello` runs a built-in one and needs no files at all:

```bash
flyte run --tracked hello
```

Use `flyte create config --local-tracked` to track every local run without passing the flag. For the full option reference, including strict reporting and run-name rules, see [Run command options](https://www.union.ai/docs/v2/union/user-guide/tasks/task-deployment/run-command-options.md). To track a run started from Python with `flyte.run()`, see [How task run works](https://www.union.ai/docs/v2/union/user-guide/tasks/task-deployment/how-task-run-works.md#tracking-a-local-run).

---

## What works locally

Most Flyte features work in both in-process and on-cluster execution. The table below summarizes how each feature behaves in-process.

| Feature | Local behavior | Details |
|---------|---------------|---------|
| **Caching** | Outputs stored in local SQLite, keyed on task name and inputs. Same inputs = instant results. | [Caching](https://www.union.ai/docs/v2/union/user-guide/tasks/task-configuration/caching.md) |
| **Tracing** | `@flyte.trace` functions appear as child nodes in the TUI with their own timing, inputs, and outputs. | [Traces](https://www.union.ai/docs/v2/union/user-guide/tasks/task-programming/traces.md) |
| **Reports** | HTML files saved locally. TUI shows the file path. | [Reports](https://www.union.ai/docs/v2/union/user-guide/tasks/task-programming/reports.md) |
| **Serving** | Run apps locally with `python serve.py` or `flyte.with_servecontext(mode="local")`. | [Serve and deploy apps](https://www.union.ai/docs/v2/union/user-guide/apps/serve-and-deploy-apps.md) |
| **Plugins** | Same decorators and APIs as remote. Secrets come from environment variables. | [Integrations](https://www.union.ai/docs/v2/union/api-reference/integrations.md) |
| **Secrets** | Read from environment variables you export, or from local files for file-mounted secrets. Flyte does not load `.env` files. No `flyte create secret` needed. | [Secrets](https://www.union.ai/docs/v2/union/user-guide/tasks/task-configuration/secrets.md) |

> [!NOTE] Visibility is the exception
> With `--tracked`, a local run also reports its state to the control plane and appears in the console.
> See [Track local runs in the console](#track-local-runs-in-the-console).

---

## From in-process to on-cluster

The same code runs in both environments. Here's what changes:

| Aspect | Local | Remote (devbox or deployed cluster) |
|--------|-------|--------|
| **Run pipeline** | `flyte run --local` | `flyte run` |
| **TUI** | `--tui` flag | Dashboard in Flyte UI |
| **Caching** | Local SQLite | Cluster-wide distributed cache |
| **Reports** | Local HTML files | Rendered in the Flyte UI |
| **Serving** | `python serve.py` | `flyte deploy serve.py env` |
| **Secrets** | Environment variables you export | `flyte create secret` / `flyte.Secret` |
| **Compute** | Your CPU/GPU | `Resources(cpu=2, memory="4Gi", gpu=1)` |

The [`TaskEnvironment`](https://www.union.ai/docs/v2/union/user-guide/get-started/core-concepts/task-environment.md) is the bridge. Locally, image and resource settings are ignored. On the cluster, Flyte builds containers and allocates compute from the same definition.

---

## Next steps

- [**Run on the devbox**](https://www.union.ai/docs/v2/union/user-guide/get-started/run-modes/running-devbox.md): Run a full Flyte cluster on your machine with Docker to test remote execution before moving to a deployed cluster.
- [**Run on a deployed cluster**](https://www.union.ai/docs/v2/union/user-guide/get-started/run-modes/running-remote.md): Configure the CLI and SDK to run on a cluster in the cloud or on-premises.

---
**Source**: https://github.com/unionai/unionai-docs/blob/main/content/user-guide/get-started/run-modes/running-locally.md
**HTML**: https://www.union.ai/docs/v2/union/user-guide/get-started/run-modes/running-locally/
