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

# Services, settings and secrets

> Give a run the database, the values and the tokens a repository's tests need.

A repository's tests often need more than the code: a database running beside them, a value CI sets, a token to install private packages. A run sets the repository up the way its CI does. What CI is handed and a run is not, you give the project once, by name.

## Services

When the repository declares a service in its CI workflow, its devcontainer or its compose file, the run starts it before the tests run. You do not have to write anything.

| | |
| - | - |
| How many | Up to 6 for a run |
| Size | 1 CPU and 2 GB of memory each |
| Where it runs | In a sandbox of its own, on a network made for this run. No other run is on that network. |
| How the tests reach it | By its name, such as `postgres:5432`, and at `localhost` on the ports it publishes |
| When it is ready | The run waits up to 90 seconds for the service to accept a connection and to pass its `ready` command |
| Cost | \$0.0025 a minute for each service, while it is up |

Reaching a service at `localhost` needs `python3` in the run's image. Without it the name still works, and the run says so.

A service that does not start, or is not ready in time, does not end the run, because the task may not need it. The timeline says what happened, so a test that fails for want of the service can be read as that.

The run's page lists the services it started, with their images. A service's environment variables are listed by name only.

![The Environment card on a run's page, listing the two services the run started from the CI workflow and the settings it was given](https://mintcdn.com/senselab/7GJRxwA5n_G2FDq5/images/sensei/run-environment.png?fit=max\&auto=format\&n=7GJRxwA5n_G2FDq5\&q=85\&s=de46c7c49ac3bab1635a53609109c808)

## Say it yourself: sensei.yaml

A file named `sensei.yaml` at the root of the repository says how to set it up. Every key is optional.

```yaml theme={null}
image: node:22-bookworm
services:
  postgres:
    image: postgres:16
    env:
      POSTGRES_PASSWORD: postgres
    ports: ["5432:5432"]
    ready: pg_isready -U postgres
  cache: redis:7
setup:
  - npm ci
  - npm run db:migrate
check: npm test
env:
  APP_ENV: test
secrets: [NPM_TOKEN]
```

| Key | Type | Description |
| - | - | - |
| `image` | string | The image the run works in |
| `services` | mapping | A name and its image, or a mapping with `image` and any of `env`, `ports`, `command` and `ready`. Up to 6. |
| `setup` | string or list | The commands run before the work, in order. One line each, up to 20. |
| `check` | string | The test command, on one line |
| `env` | mapping | Plain values every command of the run reads. Up to 60. |
| `secrets` | list | Names of the project's secrets the setup commands may use. Names only, up to 20. |

A service's name is the host name the tests reach it by: letters, digits, `-` and `_`, starting with a letter. `ready` is a command run inside the service that exits 0 once it can be used.

A key the file does not know, or a part that cannot be read, is left out. The run goes on with the rest and says which part it did not use.

A definition can carry the same `services`, `setup`, `env` and `secrets` for one agent. See the [definition reference](https://docs.sense-lab.ai/sensei/reference/definition.md#services-setup-env-and-secrets).

### Which one is used

| Order | Source |
| - | - |
| 1 | The definition |
| 2 | `sensei.yaml` |
| 3 | What the repository already declares: its CI workflow, devcontainer and compose file |
| 4 | What Sensei works out from the lockfiles |

The run's timeline names the source of each choice.

`services: {}` in a definition or in `sensei.yaml` says the tests need no service, whatever the repository's other files declare.

## Settings and secrets

A project gives its runs two kinds of value.

| | Setting | Secret |
| - | - | - |
| For | A plain value: a bucket, a region, a flag | A token or a password |
| Who reads it | Every command of every run of the project | The setup commands, and only on a run whose `sensei.yaml` or definition names it under `secrets` |
| Shown | Yes, on the project and on the run | Never. It is stored encrypted and replaced in what a run shows. |
| Refused | A value that looks like a key or a token. Save it as a secret. | A value shorter than 8 characters |

> [tab] Dashboard
>
> Open **Runs**, click **Connections** and go to **Settings and secrets**. Add a name and a value, and turn **Secret, setup only** on for a token.
>
> The same section lists the names recent runs needed and did not get, each with an **Add** button.

> [tab] Terminal
>
> ```bash theme={null}
> sensei settings set REPORTS_BUCKET reports-test
> sensei secrets set NPM_TOKEN          # prompts for the value
> sensei settings list
> sensei secrets list
> sensei secrets rm NPM_TOKEN
> ```

> [tab] Python
>
> ```python theme={null}
> sensei.settings.set("REPORTS_BUCKET", "reports-test")
> sensei.settings.set("NPM_TOKEN", token, secret=True)
> ```

A name is letters, digits and `_`, up to 64 characters, and does not start with a digit. `PATH`, `HOME`, `PWD`, `SHELL`, `USER`, `HOSTNAME`, `LD_PRELOAD` and `LD_LIBRARY_PATH` are set by the run and cannot be given. A value is up to 16,000 characters. An account can keep 200 settings and secrets.

A value saved on the dashboard is for the whole account. One saved with a key is for that key's project, and a project's value is used in place of the account's.

A setting is used in place of a value the repository's CI or devcontainer writes out. A value written in `sensei.yaml` or in a definition is used in place of the setting.

### How a secret is used

A secret reaches a run only when the run names it:

```yaml theme={null}
# sensei.yaml
setup: npm ci
secrets: [NPM_TOKEN]
```

The setup commands run in a computer of their own, with the secret in their environment. That computer is saved as an image and switched off, and the work starts in a new computer made from the image. No process from the setup is still running there, and no command of the work is given the secret. The secret's value is replaced in everything the run prints, before the model reads it and before it reaches the timeline.

Two things follow from that.

| Case | What happens |
| - | - |
| A setup command writes the secret into a file, as `npm config set` does | The file stays in the image, so the work's commands can read that file. Use a token that can only do what the setup needs. |
| The file is one the repository tracks, so the secret ends up in the change | The change is not kept, shown or pushed. The run fails and names the secret. |

What setup installs and what it writes in the repository's folder are in the image. A file it writes under `/tmp` is not: the work starts with an empty `/tmp`.

A value the tests themselves read is a setting. A secret by the same name does not reach them.

### When a run is missing a value

A CI workflow hands its tests values from the repository's own settings, such as `${{ secrets.REPORTS_BUCKET }}`. A run reads the workflow, so it knows which names the tests are handed.

| Case | What the run does |
| - | - |
| No test passes before the change, and the test output names a value the project was not given | The run ends **Failed** before any model call, and says which name. Add it and start the run again. |
| Some tests pass | The run goes on. The timeline names what is missing, and the verdict is against the tests that can run. |
| A setup command needs a secret the project does not have | The setup command fails, and the run says which name it was |

In the API such a run has `error: "missing_setting"` and the names in `result.missing`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.