---
title: "Sandbox"
description: "Configure the isolated environment where Baz builds, tests and fixes code for each repository."
canonical: "https://baz.ai/docs/integrations/sandbox"
---

# Sandbox

Configure the isolated environment where Baz builds, tests and fixes code for each repository.

A sandbox is an isolated, short-lived environment where Baz clones a repository, installs its dependencies, and runs code. The Fixer applies and validates fixes there, and Advanced Security, the Full Repo Security Scan and the SRE Agent need it too. You configure one sandbox per repository.

<span id="id-1.-what-is-a-preview-environment"></span>

## How a sandbox session runs

Each session clones your repository, runs your setup script, lets the agent edit the code, runs your validation script, then commits or opens a pull request and deletes the sandbox.

The agent can access only the cloned repository. Environment variables are encrypted and injected when the sandbox starts.

## Set up a repository

Go to **Settings → Integrations**, select **Preview Environment**, then **Sandbox**. The **Baz Sandbox Environment** table lists repositories as **Configured** or **Not configured**. For a repository that is not configured, choose one of two paths.

<Tabs>
  <Tab title="Auto-generate">
    Select **Auto-generate**. Baz detects the languages, writes an initial setup script, then runs it in a sandbox and refines it until it works. Auto-generate needs write access to the repository.
  </Tab>
  <Tab title="Set up manually">
    <Steps>
      <Step title="Open the form">
        Select **Set up manually** and pick the **Repository**.
      </Step>
      <Step title="Pick the runtime">
        Under **Runtime**, choose each language and version with **Add language** and **Add version**.
      </Step>
      <Step title="Add environment variables">
        Select **Add variable** for each **Key** and **Value**, such as private registry tokens.
      </Step>
      <Step title="Write the scripts">
        Fill in **Setup script** and, optionally, **Validation script (optional)**.
      </Step>
      <Step title="Save and test">
        Select **Save**, then **Test** to build the sandbox. The status badge moves through **Queued**, **Building** or **In Progress**, and ends at **Succeeded** or **Error**.
      </Step>
    </Steps>
  </Tab>
</Tabs>

<span id="id-2.-what-you-need-to-provide"></span>

## Fields

Pick a **Runtime** (Go, Node.js, Python, or Rust) and add any **Environment variables** your scripts need, such as `NPM_TOKEN`; stored values are masked. The **Setup script** installs dependencies before any fix, for example `npm ci`. The optional **Validation script** checks the change before Baz commits it, for example `npm run lint`.

```bash title="Setup script"
npm ci
npm run build
```

```bash title="Validation script"
npm run lint
npm test
```

## Session logs

The **Session logs** tab lists **Fixer sessions** for the repository with **PR Title**, **PR author**, **Status**, **Triggered by** and **Cost**. Open **See logs** to read each step: Setup, Lint, Review, Commit and Push.

## Generic runtime

If a repository has no sandbox, the Fixer can still run on a generic runtime with Go, Node.js, Python and Rust installed and no setup script. Turn it on with the **Generic Runtime** switch in the Fixer settings. Some fixes may fail or produce less accurate results, so configure a sandbox for repositories you fix often.

## Related

<CardGroup cols={2}>
  <Card title="Fixer" href="/docs/agents/build/fixer" icon="wrench">
    The agent that runs fixes in the sandbox.
  </Card>
  <Card title="Data protection" href="/docs/security/data-protection" icon="lock">
    How sandboxes are isolated.
  </Card>
</CardGroup>
