# GitLab CI as the merge gate: the coding agent tests on its own machine

> A coding agent that pushes to find out whether tests pass turns GitLab CI into its test runner. Keep the loop on the agent's own machine, and keep merge request pipelines, merged results and 'Pipelines must succeed' as the gate a change has to pass before it merges.

A coding agent that pushes to find out whether tests pass turns GitLab CI into its test runner. Keep the loop on the agent's own machine, and keep merge request pipelines, merged results and 'Pipelines must succeed' as the gate a change has to pass before it merges.

December 2, 2026 · 5 min read · The Sandscale team

When a team first lets Claude Code, Codex or Cursor work on a GitLab repository, a tempting pattern appears. Nobody wants the agent running tests on a developer’s laptop, so the agent pushes a commit, a merge request pipeline runs, the agent reads the job log, edits, and pushes again. GitLab CI becomes the agent’s test runner.

It works, in the sense that the tests do run somewhere other than a laptop. It is the wrong loop. This post is about the split that holds up: the agent runs the tests for the code it just changed on its own machine, and GitLab CI stays the merge gate. The GitLab behaviour comes from GitLab’s own docs on [merge request pipelines](https://docs.gitlab.com/ci/pipelines/merge_request_pipelines/) and [merge checks](https://docs.gitlab.com/user/project/merge_requests/auto_merge/), read on 2 December 2026. Sandscale commands are from CLI 1.4.1.

This is the GitLab version of a split we have already described in general terms in [why the edit-test loop should not wait on CI](https://sandscale.dev/blog/agent-edit-test-loop-should-not-wait-on-ci). It is not a walkthrough of how to run untrusted job scripts in a sandbox; our post on [GitHub Actions and agent pull requests](https://sandscale.dev/blog/github-actions-run-agent-pr-tests-in-sandbox) covers that shape for GitHub.

## What goes wrong when GitLab CI is the loop

The problems are the same ones you get when any CI system is used as a scratch runner, and they show up clearly on GitLab.

**Every iteration pays a pipeline.** An agent’s loop is many small steps: change one function, run its tests, read one failure. A merge request pipeline is built for the opposite: check out, install, build, run the jobs, report. The agent waits for all of it, plus the runners in front of it.

**The feedback is harder to read.** On its own machine, the agent runs a command and reads the output. Through GitLab it has to find the pipeline, fetch the job log and dig the failure out of output written for a person scrolling a page.

**The history fills with noise.** “fix test”, “try again”, “fix lint” become commits on the source branch that everyone then reviews.

**It spends shared runners.** GitLab runners and minutes are shared by the whole team. Several agents each pushing every few minutes can crowd out the people waiting for their own pipelines.

**It mixes two jobs.** A red pipeline can mean “the agent is still working” or “this change is broken”, and people stop trusting red.

## Where each kind of check belongs

| Check | Purpose | Where it runs |
| --- | --- | --- |
| The tests for the code the agent just changed | Fast feedback while editing | The agent’s own machine |
| Lint and type checks | Fast feedback while editing | The agent’s own machine |
| The full suite before opening or updating a merge request | Confidence before asking for review | The agent’s machine, or a larger leased machine for heavy suites |
| The required pipeline on the merge request | The gate before merge | GitLab CI |

The first two rows are the loop. The last row is the gate. It should be independent of the agent, run from a clean checkout, and be the same for people and agents.

## What GitLab already gives you for the gate

GitLab’s merge request pipelines run when you create a merge request from a source branch that has commits, when you push a new commit to that branch, or when someone selects Run pipeline on the merge request. The docs are explicit about one limit: these pipelines “run on the contents of the source branch only and ignore the content of the target branch.” To test the result of merging the two together, the docs point you at merged results pipelines.

To exist at all, a merge request pipeline needs job `rules` or `workflow: rules` in `.gitlab-ci.yml` that match `CI_PIPELINE_SOURCE == "merge_request_event"`. The docs say rules defined only in `include:` (for example `include:component`) do not satisfy that requirement; the matching rules have to be in `.gitlab-ci.yml` itself.

The merge check that makes this a gate is **Pipelines must succeed**, under Settings > Merge requests > Merge checks. GitLab’s docs say this setting also prevents a merge request from merging if there is no pipeline. If several pipeline types run for the same merge request, “Merge request pipelines have the highest priority for the Pipelines must succeed setting,” and GitLab checks only those for success.

Approvals stay a separate merge check, with their own [approval rules](https://docs.gitlab.com/user/project/merge_requests/approvals/rules/). The agent’s job is not to satisfy those; a person’s is.

None of this needs the agent to be a GitLab runner. The agent should not be pushing in order to find out whether a unit test passes.

## Why this needs a machine per agent

Teams fall back to CI because the alternative was the laptop: a developer’s machine, with their credentials, shared between several agents. CI was the only separate machine available.

Give each agent its own machine and the loop has somewhere to run. On Sandscale, each agent gets a [workspace](https://sandscale.dev/workspaces): its own Firecracker microVM with its own disk, ports, CPU and memory, where the repository, installed dependencies and the agent’s session persist. Dependencies are installed once, so running one test is just running one test.

```sh
sandscale workspace create --name bill-2290-invoices --template-id TEMPLATE_ID --ttl-seconds 28800
sandscale workspace ssh bill-2290-invoices
```

A reviewer can rerun the agent’s checks on the same machine without trusting the agent’s word for it. `workspace exec` runs one command there as you and returns the exit code and output; it asks for confirmation first:

```sh
sandscale workspace exec --ws-id WORKSPACE_ID --command '["sh", "-c", "cd ~/app && go test ./internal/billing -run TestInvoiceTotal"]'
```

For a suite that is heavier than the agent’s machine, lease a larger machine for that one step; see [leasing a build host for a full test suite](https://sandscale.dev/blog/build-host-lease-for-a-full-test-suite).

## The AGENTS.md lines

Claude Code, Codex and Cursor all read `AGENTS.md`. These lines make the split explicit for a GitLab repository:

```markdown
## Testing
- While working, run the tests for the files you changed, on this machine.
- Do not push to find out whether tests pass. Push when the checks above pass locally.
- Before opening or updating a merge request, run the full suite once.
- The merge request pipeline is the gate. If it fails on something that passed
  for you, report the difference in the merge request; do not push guesses.
- Do not edit .gitlab-ci.yml unless the task says to.
```

The important line is the second one. Without it, an agent that hits a hard failure may start pushing guesses and waiting for the pipeline, because that is what it has seen work.

## What stays in GitLab CI

Everything that makes CI a gate: the merge request pipeline (and merged results, if you use them), Pipelines must succeed, a clean checkout, the same rules for people and agents, and your approval rules. Moving the loop out of GitLab CI makes the pipeline more trustworthy, not less. Red means the change is broken, because the agent already ran its checks before it pushed.

When the task is done, stop the machine. A running machine counts toward the plan’s hours whether the agent is busy or waiting:

```sh
sandscale workspace stop --ws-id WORKSPACE_ID
```

**On this page**

1. What goes wrong when GitLab CI is the loop
2. Where each kind of check belongs
3. What GitLab already gives you for the gate
4. Why this needs a machine per agent
5. The AGENTS.md lines
6. What stays in GitLab CI

**Run your agents in a box of their own**

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

[Start free](https://cloud.sandscale.dev/auth/signup)

## Keep reading

- [December 2, 2026 · **Auditing the MCP tool calls your team's coding agents make** · When Claude Code, Codex, Cursor or Gemini CLI call MCP tools, the record of what happened can live in three places: the client, the MCP server, and the system behind it. What each layer can see, which one to trust as the record, whether to keep arguments, and how to read Sandscale's audit log for agent calls from the CLI.](https://sandscale.dev/blog/auditing-mcp-tool-calls)
- [December 2, 2026 · **Coding agents on client projects: a team lead's checklist for one machine per agent** · Services teams run Claude Code, Codex and Cursor across several client codebases at once. When those agents share developer laptops, client code, credentials and history mix. A checklist for team leads: one machine per agent per client, secrets kept per client, who can start and stop what, the audit record a client may ask for, and a clean exit at the end of the engagement.](https://sandscale.dev/blog/client-projects-one-machine-per-agent-checklist)

---
Source: https://sandscale.dev/blog/gitlab-ci-as-the-merge-gate-agent-tests-on-its-own-machine
