Software engineering teams adopting autonomous AI developer tools often encounter a frustrating bottleneck: an AI agent generates a code fix based solely on static token predictions, opens a pull request immediately, and instantly triggers a wall of failing CI checks. The team's CI pipelines get congested, engineers waste time reviewing uncompilable patches, and the promise of autonomous issue resolution dissolves into manual triage.
In Sweep, developers eliminate this problem by configuring the isolated Sandbox Test Runner inside sweep.yaml. By setting up deterministic installation commands and check routines (such as pytest or npm test), Sweep executes the test suite in an isolated runtime environment immediately after modifying code. If a test fails, Sweep captures the stack trace, feeds it back into the language model, and self-corrects across an iterative loop—only opening a pull request once all specified tests pass.
Why Purely Static Generation Breaks CI
When an AI coding assistant operates without execution feedback, it relies entirely on internal statistical probabilities and repository context. Even advanced language models routinely produce code with subtle regressions:
- Calling deprecated or non-existent method signatures.
- Introducing type mismatches that evade superficial syntax parsing.
- Solving the targeted bug while inadvertently breaking adjacent boundary conditions.
- Forgetting necessary import statements or environment assumptions.
If the agent pushes code directly to GitHub, your central CI runner (e.g., GitHub Actions) becomes the first line of defense. This approach creates significant engineering drag:
- CI Pipeline Congestion: Automated bots trigger expensive cloud runner minutes for trivial syntax errors or missed assertions.
- Alert Fatigue: Team communication channels get flooded with broken build notifications.
- Manual Context Switching: Human reviewers must review and comment on PRs that should never have left the development harness.
Sweep addresses this by establishing two distinct testing tiers:
| Testing Tier | Execution Point | Primary Role | Ideal Scope |
|---|---|---|---|
Sandbox Test Runner (sandbox) | Pre-PR (within Sweep agent loop) | Catch syntax errors, broken contracts, and unit regressions before pushing code | Fast unit tests, linters, type-checkers (< 60s) |
GitHub Actions Monitoring (gha_enabled: true) | Post-PR (central CI infrastructure) | Catch multi-service integration, deployment, and end-to-end regressions | Integration tests, E2E suites, multi-platform builds |
At 365Finds, our assessment is clear: relying on post-PR GitHub Actions alone is an anti-pattern for autonomous agents. The sandbox test runner is the critical gatekeeper that separates viable autonomous development from noisy code hallucination.
How the Sweep Sandbox Execution Loop Works
The Sweep sandbox is an isolated containerized runtime environment designed to validate code modifications on the fly. Its lifecycle consists of three distinct phases:
[Issue Trigger]
│
▼
1. Sandbox Setup (sandbox.install runs once)
│
▼
2. AI Generates / Modifies Code
│
▼
3. Execution Validation (sandbox.check commands)
│
┌───┴────────────────────────┐
▼ ▼
[Tests Fail (Exit != 0)] [Tests Pass (Exit == 0)]
│ │
▼ ▼
Log Extraction & Filtering Commit Changes & Open PR
│
▼
LLM Diagnoses Error & Re-edits
│
└───────────► (Repeat Loop)
- Environment Setup (
sandbox.install): When Sweep begins work on an issue, it provisions a fresh container environment and executes the commands listed insandbox.install. This installs the necessary system utilities, compilers, language runtimes, and package dependencies. - Check Execution (
sandbox.check): After generating code for a target file, Sweep executes the commands insandbox.checkin sequential order. These commands typically invoke linters, formatters, type-checkers, and test runners. If a command uses the{file_path}placeholder, Sweep substitutes the relative path of the file it just changed. - The Self-Correction Loop:
If any command in
sandbox.checkreturns a non-zero exit code, Sweep halts the commit workflow. It captures stdout and stderr, applies heuristic filters to discard setup noise, and extracts the core stack trace and assertion failure. This error output is fed back into the agent prompt. The model diagnoses the failure, adjusts its implementation, and triggerssandbox.checkagain. This cycle repeats until all commands pass or the execution iteration threshold is reached.
Configuring sweep.yaml for Automated Testing
To configure sandbox test execution, place a sweep.yaml configuration file in the root directory of your repository. Below are battle-tested configurations for standard technology stacks.
1. Python (Poetry + pytest + ruff)
In a Python project, fast linting and targeted unit tests provide the highest signal-to-noise ratio:
# sweep.yaml
branch: "main"
gha_enabled: true
sandbox:
install:
- apt-get update && apt-get install -y python3.11 python3-pip
- pip install poetry
- poetry install
check:
- poetry run ruff check {file_path}
- poetry run pytest tests/unit/ -q --maxfail=1
rules:
- "Write unit tests alongside code or under tests/unit/."
- "Ensure all pytest test cases pass cleanly before completing changes."
In this setup:
sandbox.installbootstraps Python 3.11, installs Poetry, and resolves virtual environment dependencies.sandbox.checkfirst runs Ruff against the specific edited file ({file_path}) to catch syntax or lint defects instantly, then runs the unit test suite viapytest. The--maxfail=1flag ensures the test runner halts on the first failure, giving Sweep a concise error log without context-window clutter.
2. TypeScript / Node.js (npm / yarn + Vitest / Jest + ESLint)
For full-stack or JavaScript/TypeScript applications:
# sweep.yaml
branch: "main"
gha_enabled: true
sandbox:
install:
- npm ci
check:
- npx prettier --check {file_path}
- npx eslint {file_path}
- npm test -- --runInBand --testPathPattern=tests/unit
Key considerations for Node.js environments:
- Use
npm cirather thannpm installinsandbox.installto ensure reproducible, fast installs frompackage-lock.json. - Pass
--runInBandto Jest or Vitest to run tests sequentially, avoiding thread contention and erratic timeouts inside containerized sandboxes. - Restrict
testPathPatternto unit tests.
3. Multi-Language Repositories (Trunk Super-Linter + Test Suites)
If your repository spans multiple languages, Sweep natively supports Trunk:
# sweep.yaml
branch: "main"
sandbox:
install:
- trunk init
- pip install -r requirements.txt
check:
- trunk fmt {file_path}
- trunk check {file_path}
- pytest tests/
Trunk standardizes code formatting and static analysis across languages, while your test command validates core business logic.
Testing Your Configuration Locally with sweep-sandbox
Before deploying sweep.yaml to your production repository, you should verify that your setup and check scripts execute cleanly without errors. Sweep provides an official CLI utility named sweep-sandbox for local validation.
Installation
Install sweep-sandbox on your local terminal using the official installation script:
curl https://raw.githubusercontent.com/sweepai/sweep/main/bin/install_sweep_sandbox.sh | sh
Running Validation
From the root directory of your repository, run the CLI against a modified file:
sweep-sandbox src/example.py
sweep-sandbox parses your local sweep.yaml, executes the install instructions inside a local container or shell environment, and runs each check command against the targeted file. If an exit code is non-zero or paths are misconfigured, you can fix them locally before letting Sweep operate autonomously on GitHub.
365Finds Institutional Judgments & Best Practices
At 365Finds, we recommend adhering to three strict architectural guidelines when configuring Sweep sandboxes:
- Enforce the 60-Second Unit Test Rule:
Do not run browser tests (Playwright/Cypress), heavy database migrations, or end-to-end suites in
sandbox.check. Sandbox execution runs synchronously inside the agent's reasoning loop. Slow test suites cause execution timeouts, consume token quotas, and inflate iteration times from seconds to 15+ minutes. Keepsandbox.checkstrictly focused on unit tests and fast linters (< 60 seconds total runtime). Leave broad integration suites to GitHub Actions post-PR. - Isolate Sandbox Tests from External Network Services: Never allow sandbox unit tests to depend on live third-party APIs. If an external service rate-limits the sandbox or drops a connection, the test suite exits with an error. The LLM will misinterpret the network failure as a bug in its own code and hallucinate unnecessary logic changes trying to fix a remote infrastructure hiccup. Enforce mock adapters or local stubs for all sandbox tests.
- Keep
sandbox.installMinimal and Deterministic: Avoid running general package upgrades (apt upgrade -yor unpinnedpip install) duringinstall. Unpinned dependencies cause non-deterministic failures when external mirrors update upstream packages. Pin your dependency manifests and commit lockfiles (poetry.lock,package-lock.json) to keep container boot times predictable and fast.
When properly configured, sweep.yaml transforms Sweep from an unpredictable code generator into a disciplined, self-testing developer capable of delivering reliable, review-ready pull requests.