> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stably.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Setup Script

> Run a custom bash script during cloud agent session initialization to prepare your environment before tests run.

## Overview

The `cloud.setupScript` field in `stably.yaml` allows you to run a bash script during agent session initialization. This is useful for projects that have CI-generated files not in the repository but required for tests to run.

<Info>
  **When to use `cloud.setupScript` vs `postinstall`**: Use `cloud.setupScript` for setup that should only run in Stably's cloud environment. If you need the same setup to run locally and in your own CI, add it to your `postinstall` script instead.
</Info>

***

## Use Cases

| Scenario              | Example                                                 |
| --------------------- | ------------------------------------------------------- |
| **Auth/config files** | Create files that are generated by CI but not committed |
| **Codegen scripts**   | Run GraphQL, Prisma, or other code generation           |
| **Test fixtures**     | Set up environment-specific test data                   |
| **Pre-test setup**    | Any setup that isn't part of `npm install`              |

***

## Configuration

Add a `cloud` section to your `stably.yaml` with a `setupScript` field:

```yaml stably.yaml theme={null}
cloud:
  setupScript: |
    npm run codegen
    npm run generate:fixtures
```

### Configuration Options

| Field               | Type   | Required | Description                                                                                           |
| ------------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------- |
| `cloud.setupScript` | string | No       | Bash script to run during session initialization. Use YAML literal block style for multi-line scripts |

<Note>
  Stably automatically runs dependency installation (`npm install`, `pnpm install`, etc.) before your setup script executes. You don't need to include dependency installation commands in your script.
</Note>

<Tip>
  Your script runs from the directory where `stably.yaml` is located.
</Tip>

***

## Related Configuration

The `stably.yaml` file supports additional configuration for other Stably features:

<CardGroup cols={2}>
  <Card title="Scheduled Runs" icon="clock" href="/run-tests/scheduled-runs">
    Configure automated test schedules with cron expressions
  </Card>

  <Card title="CLI Agent Configuration" icon="terminal" href="/stably-cli/commands#agent-configuration">
    Customize `stably fix` behavior with rules and limits
  </Card>
</CardGroup>
