---
title: "Environments"
description: "Configure multi-repo cloud environments with .company/environment.json, install and startup scripts, build logs, and warm snapshots."
url: "https://www.thecompany.company/docs/code/environments"
---

# Environments

> Configure multi-repo cloud environments with .company/environment.json, install and startup scripts, build logs, and warm snapshots.

An environment defines which repositories, machine size, and setup commands prepare a fresh cloud [computer](/docs/agent/computer) for coding sessions. When an environment installs dependencies, starts services, and runs your test suite, agents can verify changes before opening a pull request instead of guessing.

![An environment's overview with its name and machine size](https://www.thecompany.company/docs/screenshots/light/environment-setup.webp)

Inspect an environment's settings, with its snapshots and builds a tab away.

## Setup [#setup]

1. ### Sync your repositories [#sync-your-repositories]

   Make sure the repositories you need are connected under [**Settings → Repositories**](/docs/code/repositories).
2. ### Create the environment [#create-the-environment]

   As an organization owner or admin, open **Settings → Environments → New environment**. Enter a name, select a machine size and one or more repositories, and select **Create**.
3. ### Select it in new sessions [#select-it-in-new-sessions]

   Choose the environment when starting a coding session. If a repository does not appear, check both the GitHub App installation access and the environment's **Repositories** list.

## Repository configuration [#repository-configuration]

Store repository setup in `.company/environment.json` so your team can review environment changes in pull requests. Put heavy dependency installation in `scripts.install` so snapshots cache it, and keep branch-checkout preparation fast and repeatable:

```json
{
  "$schema": "https://api.thecompany.company/schemas/v1/environment.json",
  "scripts": {
    "install": {
      "command": "bun install --frozen-lockfile",
      "timeout": 900
    },
    "prepare": {
      "command": "bun run db:generate",
      "timeout": 300
    },
    "start": {
      "command": "bun run dev"
    }
  },
  "env": {
    "NODE_ENV": "development"
  }
}
```

| Field | Purpose |
| --- | --- |
| `scripts.install` | Install dependencies, toolchains, and build caches during snapshot builds. |
| `scripts.prepare` | Run a quick, repeatable refresh step after checking out a branch. |
| `scripts.start` | Start background services (databases, local dev servers) the repository needs. |
| `env` | Set non-secret environment variables. Store credentials in [Secrets](/docs/code/secrets), never in Git. |

> Inspect the API repository and draft `.company/environment.json`. Verify the install command on this computer and open a draft PR with just the setup file.

> Inspect the latest failed build for the API environment. Identify the first failing command and explain how to fix it without changing any settings.

## Builds and snapshots [#builds-and-snapshots]

A successful build captures the post-setup filesystem into a warm **snapshot**, so new cloud computers boot with repositories and dependencies already on disk.

- **Inspect build logs:** Open **Builds** to review each build attempt and per-repository command output.
- **Check active snapshots:** Open **Snapshots** to see which snapshot new computers will start from.
- **Rebuild after fixes:** If a setup command fails, fix the configuration and select **Rebuild**. Creating an environment with repositories starts an initial build automatically; adding or removing repositories or changing machine size can also trigger a new build.
- **Running computers stay untouched:** A new snapshot applies only to newly started computers and does not overwrite a computer that is already running.

## Troubleshooting [#troubleshooting]

- **Repository missing in a session:** Verify the repository is granted to the GitHub App and listed under the environment's **Repositories** tab.
- **Build fails during setup:** Open **Builds** to inspect the first failing command and its output. Previous active snapshots remain usable until a replacement build succeeds.
- **Changes not reflected in an active session:** Start a new session or boot a new computer after a snapshot finishes building; running computers keep the snapshot they started with.

## Next steps [#next-steps]

- [Secrets](https://www.thecompany.company/docs/code/secrets.md): Inject encrypted credentials needed by setup scripts and tests.
- [Computer](https://www.thecompany.company/docs/agent/computer.md): Work in cloud computers, preview local apps, and isolate worktrees.
- [Repositories](https://www.thecompany.company/docs/code/repositories.md): Sync repositories and set Git attribution.
- [Pull requests](https://www.thecompany.company/docs/code/pull-requests.md): Open draft PRs and verify CI checks.
