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

> ## Agent Instructions
> ## XenoCI Box CI
> To move a repository's macOS CI jobs onto box, follow https://docs.xenoci.com/ci/agent.md. The user only presses Install on GitHub or makes one GitLab runner token; the agent does the rest.
> - Check: `box ci status` (exit 4: sign in first, https://docs.xenoci.com/setup.md).
> - GitHub organization: `box ci connect --org --no-browser --no-wait`, give the user the printed link (https://github.com/apps/xenoci-with-organizations/installations/new), then repeat `box ci accounts` until the owner appears. Personal account: `--personal` (https://github.com/apps/xenoci-with-personal/installations/new).
> - GitHub workflow: change only `runs-on: macos-*` to `runs-on: xenoci` on a branch and open a pull request.
> - GitLab: the user makes a project runner with tag `xenoci` and gives you the `glrt-` token; pipe it to `box ci gitlab connect -` (self-managed: `--url <gitlab url>`), then add `tags: [xenoci]` to the macOS jobs.
> - Watch: `box ci jobs`, `box ci logs <job id> --follow`. Failed job: `box ci jobs --failed`, then `box ci debug <job id>` (failing step, hint, last 200 log lines).

# Fall back from a self-hosted runner to a hosted one

> GitHub Actions does not reroute a job when its self-hosted Mac is offline. Pick the runner in a small job first, and keep fork pull requests off your machine.

> [!NOTE]
>
> **Try it now:** paste this line into Claude Code, Codex or Cursor. It installs box, signs you in with GitHub and runs your first build:
>
> ```text theme={"system"}
> Set up XenoCI Box with https://docs.xenoci.com/setup
> ```
>
> Your first sign-in adds \$10 of credit, about 200 Mac minutes (once per GitHub account).

A common plan for iOS CI is "run on our own Mac, and use a GitHub-hosted macOS runner when the Mac is offline". `runs-on` cannot express that by itself. A job whose labels match no online runner waits in the queue (up to 24 hours); GitHub does not move it to another label.

So the choice has to be made before the job starts.

## Pick the runner in a small job

A job on `ubuntu-latest` asks the API which runners are online and idle, then outputs a JSON label list. The macOS job reads it with `fromJSON`:

```yaml theme={"system"}
jobs:
  pick-runner:
    runs-on: ubuntu-latest
    outputs:
      label: ${{ steps.p.outputs.label }}
    steps:
      - id: p
        env:
          GH_TOKEN: ${{ secrets.RUNNER_READ_TOKEN }}
          SAME_REPO: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }}
        run: |
          label='["macos-26"]'
          if [ "$SAME_REPO" = true ]; then
            idle=$(gh api repos/${{ github.repository }}/actions/runners \
              --jq '[.runners[] | select(.status=="online" and .busy==false) | select(any(.labels[]; .name=="mini"))] | length')
            [ "$idle" -gt 0 ] && label='["self-hosted","macos","mini"]'
          fi
          echo "label=$label" >> "$GITHUB_OUTPUT"

  ios-tests:
    needs: pick-runner
    runs-on: ${{ fromJSON(needs.pick-runner.outputs.label) }}
    steps:
      - uses: actions/checkout@v4
      - run: xcodebuild -scheme App -destination 'platform=iOS Simulator,name=iPhone 16' test
```

Notes:

* Listing runners needs a token with the repository's *Administration: read* permission. The default `GITHUB_TOKEN` cannot list runners, so use a fine-grained token stored as a secret.
* Fork pull requests do not receive that secret, and the `SAME_REPO` check sends them to the hosted label anyway. On a public repository this keeps code from forks off your Mac.
* `busy` can change between the check and the job start. Two pull requests may both pick your Mac; the second one then waits for the first. Add `concurrency` to the self-hosted path if you want that to be explicit.

## Keep the Mac clean between jobs

A runner registered with `./config.sh --ephemeral` takes one job and removes itself, so a small loop (for example a launchd job) has to register it again with a fresh registration token before each job. The same loop is a good place to delete build output and old simulators:

```bash theme={"system"}
rm -rf "$HOME/ci/DerivedData"
xcrun simctl delete unavailable
```

## Or skip the fallback

If you would rather not keep a Mac online for CI, box runs the macOS jobs on a fresh Mac per job. Connect the repository and change the runner line:

```bash theme={"system"}
box ci connect --personal
```

```yaml theme={"system"}
  ios-tests:
    runs-on: xenoci
```

See [GitHub Actions setup](https://docs.xenoci.com/ci/github.md).

Related: [macOS job was not acquired](https://docs.xenoci.com/guides/macos-job-not-acquired.md), [GitHub Actions macOS runner alternative](https://docs.xenoci.com/guides/github-actions-macos-runner-alternative.md), [CI on Macs](https://docs.xenoci.com/ci.md).

[Start with \$10 of credit, about 200 Mac minutes](https://docs.xenoci.com/setup?ref=docs-self-hosted-runner-fallback).


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