> For the complete documentation index, see [llms.txt](https://docs-lunar.earthly.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-lunar.earthly.dev/install/lunar-ci-agent/agent-managed.md).

# Managed Runners

The [`earthly/lunar-ci-tracer`](https://github.com/earthly/lunar-ci-tracer) action is the easiest way to add the Lunar CI Agent to your GitHub Actions workflows. It works with both **GitHub-hosted** and **self-hosted** runners.

For **GitHub-hosted runners** (managed runners), this action is the only installation method — you cannot modify the runner startup process.

For **self-hosted runners**, you can either use this action or configure the agent to [wrap the runner's `run.sh` command](/install/lunar-ci-agent/agent-self-hosted.md) directly, which avoids adding a step to every job.

## Setup

Add the Lunar CI Tracer action as an early step in your workflow jobs:

```yaml
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Run Lunar CI Tracer
        id: lunar
        uses: earthly/lunar-ci-tracer@<latest-tag>
        env:
          LUNAR_HUB_TOKEN: ${{ secrets.LUNAR_HUB_TOKEN }}
          LUNAR_HUB_HOST: your_hub_host

      - uses: actions/checkout@v5
      # ... rest of your workflow
```

The action installs the `lunar` CLI for you (no pre-install step needed) and runs `lunar ci-tracer run`, which fetches the agent through your Lunar Hub on first use, verifies it, and attaches it to the job process. All subsequent steps in the job are automatically instrumented. Your Hub must be reachable when the action starts.

## How It Works

The action runs as a step in a job. It downloads the `lunar` CLI, then runs `lunar ci-tracer run`, which fetches the agent through your Hub on first use and execs it. The agent attaches to the current shell process via ptrace and traces all commands executed by subsequent steps. The agent exits automatically when the job completes.

The same [configuration reference](/install/lunar-ci-agent/agent-config.md) applies. The only difference is that `LUNAR_RUN_CMD` is not needed — the action handles process supervision internally.

{% hint style="warning" %}
For self-hosted runners that require the use of `sudo` in workflows, the `CAP_SYS_ADMIN` capability should be provided — see [Running `sudo` and setuid binaries in traced workflows](/install/lunar-ci-agent/agent-self-hosted.md).
{% endhint %}

## Failure Handling

Agent installation failures (CLI download, agent download through the Hub, agent startup) are gated by `LUNAR_STRICT_MODE`:

* `LUNAR_STRICT_MODE=true` — the step **fails** with the error output.
* Unset or `false` (default) — the action emits an `::error::` annotation plus a warning, sets the `agent-installed` output to `false`, and the step **succeeds** so the rest of the job continues uninstrumented.

The action exposes an `agent-installed` output (`'true'` / `'false'`) so downstream steps can branch on whether instrumentation is active:

```yaml
- name: Run checks that need the tracer
  if: steps.lunar.outputs.agent-installed == 'true'
  run: ./run-traced-tests.sh
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs-lunar.earthly.dev/install/lunar-ci-agent/agent-managed.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
