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

# Run CI jobs in sandboxes

> Let AutoPilot for CI run GitHub Actions jobs on one-job runners in sandboxes from your own sandbox provider account.

> [!NOTE]
>
> Running CI jobs in sandboxes is in preview.

[AutoPilot for CI](https://docs.costgraph.ai/costgraph/autopilot/ci.md) can run a job in a sandbox from
your own provider account. CostGraph starts a fresh sandbox with a GitHub
Actions runner that takes only that job. The sandbox is deleted when the job
ends. [Supported sandbox providers](https://docs.costgraph.ai/costgraph/workflows/sandbox-providers.md)
lists the providers that can run CI jobs.

Sandbox runners compete like any other runner, under your
[policy](https://docs.costgraph.ai/costgraph/autopilot/ci.md#policies),
[trials](https://docs.costgraph.ai/costgraph/autopilot/ci.md#try-new-runners), and
[provider limits](https://docs.costgraph.ai/costgraph/autopilot/ci-settings.md#provider-limits). A job's
cost is the provider's published price for the sandbox size, for as long as the
sandbox runs. Your provider bills that time to your account.

## Requirements

* AutoPilot for CI is set up as described in [Requirements](https://docs.costgraph.ai/costgraph/autopilot/ci.md#requirements).
* An owner of the GitHub organization has approved the CostGraph GitHub App's
  **Self-hosted runners** organization permission, set to **Read and write**,
  and its **Workflow job** event. Until then, sandboxes are skipped with reason
  `github_app_reapproval`.
* A sandbox provider is connected on Integrations, as described in
  [Connect](https://docs.costgraph.ai/costgraph/workflows/managed-sandboxes.md#connect).
* Jobs run on Linux, on `x64` or `arm64`.

## Runner image

Providers that boot a container image, such as Beam, Daytona, Fly, Islo, and
Promigence, start the CostGraph CI runner image,
`ghcr.io/baselinehq/costgraph-ci-runner`. It is GitHub's runner image on
Ubuntu 24.04 with most tools from GitHub's `ubuntu-latest` image. It includes
Node.js with pnpm and Yarn, Python, Go, Java 17 and 21 with Maven, and Rust.
It also includes the GitHub CLI, the AWS CLI, kubectl, Helm, Terraform, and
Docker with buildx and compose.

Other providers start from their own default image. CostGraph installs the
GitHub Actions runner, git, curl, jq, Python, build tools, and Node.js when the
sandbox boots, and Docker when the job needs it. These installs need root or
sudo and `apt-get` in the sandbox.

The job runs as a `runner` user with passwordless sudo when the sandbox allows
it, and as root otherwise. Install anything else the job needs in the workflow,
with a `setup-*` action or `sudo apt-get install -y <package>`.

## Send a job to a sandbox

You can send a job to a sandbox in three ways.

* **Routing job.** With the [routing job](https://docs.costgraph.ai/costgraph/autopilot/ci.md#add-the-routing-job)
  in place, sandboxes become candidates for every job that fits them.
* **Pin.** Set `pin` on the routing job to a sandbox provider, such as `beam`,
  or a size, such as `beam:sandbox-8c-32g`. Refer to
  [Pin a workflow to a provider](https://docs.costgraph.ai/costgraph/autopilot/ci.md#pin-a-workflow-to-a-provider).
* **CostGraph label.** Write a label that starts with `costgraph=` in
  `runs-on` to run the job in a sandbox without a routing job.

The following job uses a CostGraph label.

```yaml theme={null}
jobs:
  test:
    runs-on: costgraph=${{ github.run_id }}-${{ strategy.job-index }}/cpu=4/ram=16
    steps:
      - uses: actions/checkout@v5
      - run: make test
```

The label starts with `costgraph=` and a value unique to the job. The optional
parts after it say what the job needs.

| Part | Meaning |
| - | - |
| `cpu=<n>` | At least `n` vCPUs. |
| `ram=<gb>` | At least this many GB of memory. |
| `arch=x64` or `arch=arm64` | The CPU architecture. |
| `docker` | The job runs Docker. |

Only sandboxes compete for a job with a CostGraph label. To compare them with a
runner you know, set a [baseline runner](#settings).

## When a runner does not start

* A runner that has not started 60 seconds after its sandbox was requested is
  tried once on the next best sandbox.
* A job with a CostGraph label that has no runner after 2 minutes gets one on
  the next best sandbox. After the fallback delay, it goes to the fallback
  runner, when you set one.
* A sandbox still running after 6 hours is deleted.

A routed job that never gets a runner is handled like any
[stuck job](https://docs.costgraph.ai/costgraph/autopilot/ci.md#stuck-jobs). A provider whose latest
runner never started is offline for every job, for example when the size is
larger than your plan's vCPU limit. Refer to
[Try new runners](https://docs.costgraph.ai/costgraph/autopilot/ci.md#try-new-runners).

## Settings

Set these on the **Settings** tab of AutoPilot for CI, for the organization, a
repository, or a workflow, or with the
[settings API](https://docs.costgraph.ai/costgraph/autopilot/ci-settings.md#sandbox-runners).

| Setting | Meaning |
| - | - |
| Fallback runner | The connected sandbox a job with a CostGraph label goes to when no other sandbox started it. |
| Fallback delay | Seconds before the fallback runner gets the job. At least 60, and 300 by default. |
| Baseline runner | The runner that jobs with a CostGraph label are compared with for policy, trials, and savings. |

## Run your own dispatcher

CostGraph starts sandboxes for you by default. If you self-host CostGraph, need
runners on a private network, or want to keep the provider key out of
CostGraph, run your own dispatcher. Install the
[agent runtime chart](https://docs.costgraph.ai/costgraph/workflows/managed-sandboxes.md#run-your-own-dispatcher)
with your provider's credentials and turn on CI runners.

```yaml theme={null}
dispatcher:
  workerName: ci-fly
  existingSecret: costgraph-sandbox-key
  sandbox:
    provider: fly
    providerSecret: sandbox-provider
  ciRunner:
    enabled: true
    arch: x86_64
```

The provider credentials stay in your cluster. `dispatcher.concurrency` sets
how many jobs the dispatcher runs at once. On providers that build their own
templates, set `dispatcher.ciRunner.providerTemplate` to a template built from
the [runner image](#runner-image), so jobs start faster and have its tools.

## Docker

Docker, including `services:` and `container:` jobs, works where the provider
can run a Docker daemon. Set `docker: true` on the routing job or `docker` in
the CostGraph label, so AutoPilot offers only providers that can run Docker.

On Beam, containers on Docker's default bridge network have no outbound
network. Build images with `docker build --network host` when the build
downloads anything.

## Secrets and forks

Jobs with secrets can run in sandboxes by default. To keep them off a sandbox
provider, set [`allow_secrets: false`](https://docs.costgraph.ai/costgraph/autopilot/ci-settings#provider-limits)
for it.

CostGraph never starts a sandbox runner for a pull request from a fork or a
`pull_request_target` run. It cancels such a run when a job has a CostGraph
label. Use the routing job in workflows that forks trigger, so their jobs keep
their default runners.

## Network and public repositories

The runner connects out to GitHub over HTTPS on port 443 and opens no inbound
port. If your provider limits egress, allow the domains GitHub lists for
[self-hosted runners](https://docs.github.com/en/actions/reference/runners/self-hosted-runners#accessible-domains-by-function).

Sandbox runners join your organization's **Default** runner group. By default,
GitHub doesn't let that group run jobs from public repositories, so those jobs
never get a runner. To allow them, an organization owner opens **Settings >
Actions > Runner groups** in GitHub and turns on **Allow public repositories**
for the **Default** group. Read GitHub's
[guidance on self-hosted runners and public repositories](https://docs.github.com/en/actions/reference/security/secure-use#hardening-for-self-hosted-runners)
before you turn it on.

## Related

* [AutoPilot for CI](https://docs.costgraph.ai/costgraph/autopilot/ci.md)
* [AutoPilot for CI settings](https://docs.costgraph.ai/costgraph/autopilot/ci-settings.md)
* [Run workflows on a managed sandbox provider](https://docs.costgraph.ai/costgraph/workflows/managed-sandboxes.md)


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