AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Configure Sandbox Test Execution in sweep.yaml to Verify Bug Fixes Before Pull Requests

沈妍婷 · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

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:

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:

  1. CI Pipeline Congestion: Automated bots trigger expensive cloud runner minutes for trivial syntax errors or missed assertions.
  2. Alert Fatigue: Team communication channels get flooded with broken build notifications.
  3. 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 TierExecution PointPrimary RoleIdeal Scope
Sandbox Test Runner (sandbox)Pre-PR (within Sweep agent loop)Catch syntax errors, broken contracts, and unit regressions before pushing codeFast 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 regressionsIntegration 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)
  1. Environment Setup (sandbox.install): When Sweep begins work on an issue, it provisions a fresh container environment and executes the commands listed in sandbox.install. This installs the necessary system utilities, compilers, language runtimes, and package dependencies.
  2. Check Execution (sandbox.check): After generating code for a target file, Sweep executes the commands in sandbox.check in 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.
  3. The Self-Correction Loop: If any command in sandbox.check returns 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 triggers sandbox.check again. 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:

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:

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:

  1. 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. Keep sandbox.check strictly focused on unit tests and fast linters (< 60 seconds total runtime). Leave broad integration suites to GitHub Actions post-PR.
  2. 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.
  3. Keep sandbox.install Minimal and Deterministic: Avoid running general package upgrades (apt upgrade -y or unpinned pip install) during install. 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.


References