Sandbox
The sandbox executes a set of commands to validate Sweep's changes using linters and type-checkers after every edit. By default we use Trunk (opens in a new tab), an opinionated super-linter that installs all the common formatters and linters for your codebase.
To get started with the setup run the following installation script in the background, then follow the instructions below to set up your config:
curl https://raw.githubusercontent.com/sweepai/sweep/main/bin/install_sweep_sandbox.sh | sh
Configuration
Go to your local clone of your repo. Create your sweep.yaml
if it doesn't already exist and copy the following template into it:
TemplateΒ sweep.yaml
Β to copy
# Sweep AI turns bug fixes & feature requests into code changes (https://sweep.dev)
# For details on our config file, check out our docs at https://docs.sweep.dev
# If you use this be sure to frequently sync your default branch(main, master) to dev.
branch: 'main'
# By default Sweep will read the logs and outputs from your existing Github Actions. To disable this, set this to false.
gha_enabled: True
# This is the description of your project. It will be used by sweep when creating PRs. You can tell Sweep what's unique about your project, what frameworks you use, or anything else you want.
# Here's an example: sweepai/sweep is a python project. The main api endpoints are in sweepai/api.py. Write code that adheres to PEP8.
description: ''
# Default Values: https://github.com/sweepai/sweep/blob/main/sweep.yaml
Sweep uses our own Sandbox base image based this Dockerfile (opens in a new tab), and first installs everything in the install
section. Then on every edit, it runs the commands in the check
section for the edited file. When it errors (non-zero return code), the logs get fed back into Sweep to fix the error, guaranteeing that every commit generates validated code.
By default we use Trunk, an opinionated super-linter that installs all the common formatters and linters for your codebase. You can set up and configure Trunk for yourself by following https://docs.trunk.io/get-started (opens in a new tab). This is equivalent to having the following sandbox
config in your sweep.yaml
:
Default Sweep sandbox setup: Trunk
sandbox:
install:
- trunk init
check:
- trunk fmt {file_path}
- trunk check --fix {file_path}
However, you can set up custom commands for your Sandbox. Here are some example sweep.yaml
sandbox configurations:
Python withΒ pylint
Here's an example sweep.yaml
for a Python repo that uses pylint
.
sandbox:
install:
- pip install -r requirements.txt
check:
- pylint --errors-only {file_path}
Sweep's Own Config: Python 3.11, Poetry, and Β pylint
Sweep's own repo's sweep.yaml
Python 3.11, Poetry and pylint
.
sandbox:
install:
- apt install python3.11 -y
- pip install poetry
- poetry env use python3.11
- poetry install
check:
- poetry run pylint --errors-only {file_path}
Sweep's landing page: Yarn withΒ prettier
,Β eslint
Β andΒ tsc
Our landing page, which is Typescript-based, we have the following config:
sandbox:
install:
- yarn install --ignore-engines
check:
- yarn run prettier --write {file_path}
- yarn run eslint {file_path}
- yarn run tsc
We recommend starting with the formatters, followed by the linters and type-checkers. This is because formatters give clear error messages for syntax errors.
Testing
To ensure that your sandbox is set up properly, you can test it locally.
If you ran the installation script at the top, sweep-sandbox
should be fully installed by now. Ensure that sweep-sandbox
is installed properly by running sweep-sandbox --help
. Then execute the following in the base of your repo in the following format:
sweep-sandbox FILE_PATH
Replacing FILE_PATH with the file or directory you want sweep-sandbox
to run on. For example in the Sweep repo, we run sweep-sandbox sweepai
to run pylint
on the entire sweepai
directory and sweep-sandbox sweepai/api.py
to check the single file api.py
.