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

# Environments

> Reference for the `environments` array in `momentic.config.yaml`. Each environment defines a base URL and a set of variables (including secrets) available to tests.

Define one or more environments to run tests against. Each provides a `baseUrl`
and a set of [variables](/core-concepts/variables) available to tests as
`env.*`.

```yaml momentic.config.yaml theme={null}
environments:
  - name: dev
    baseUrl: https://dev.example.com
    envVariables:
      USERNAME: devUser
      PASSWORD: devPassword
  - name: staging
    baseUrl: https://staging.example.com
    envVariables:
      USERNAME: stagingUser
      PASSWORD: stagingPassword
  - name: production
    baseUrl: https://www.example.com
    envVariables:
      USERNAME: prodUser
      PASSWORD: prodPassword
```

For details on how Momentic resolves variables at runtime, see
[Environment variables](/configuration/environment-variables).

## Environment isolation

By default, Momentic shares cache entries across environments in the same
project. This keeps repeat runs fast when `dev`, `staging`, and `production`
render the same UI.

If environments have different DOM structures, mobile screens, feature flags, or
environment-specific IDs, enable
[`advanced.isolateCachesByEnvironment`](/configuration/advanced#advanced-isolatecachesbyenvironment).
When enabled, Momentic stores separate [step cache](/reliability/step-cache)
entries for each selected environment, so a cache learned in `staging` will not
replay in `production`.

```yaml momentic.config.yaml theme={null}
environments:
  - name: staging
    baseUrl: https://staging.example.com
  - name: production
    baseUrl: https://www.example.com

advanced:
  isolateCachesByEnvironment: true
```

## Per-environment options

<ParamField path="environments[].name" type="string">
  Name of the environment. Selected at runtime via `--env <name>` and exposed
  to tests as `env.ENV_NAME`.

  ```yaml momentic.config.yaml theme={null}
  environments:
    - name: dev
  ```
</ParamField>

<ParamField path="environments[].baseUrl" type="string">
  Starting URL for tests in this environment. Exposed as `env.BASE_URL`.

  ```yaml momentic.config.yaml theme={null}
  environments:
    - name: dev
      baseUrl: https://dev.example.com
  ```
</ParamField>

<ParamField path="environments[].envVariables" type="Record<string, string | { fromFile: string; json?: boolean }>">
  Key-value pairs available to tests as `env.VARIABLE_NAME`. Values may
  reference shell variables via
  [dotenvx interpolation](https://dotenvx.com/docs/env-file#interpolation),
  but cannot reference other variables defined in the same `envVariables`
  block.

  ```yaml momentic.config.yaml theme={null}
  environments:
    - name: dev
      envVariables:
        USERNAME: devUser
        API_KEY: ${VAR_FROM_SHELL:-default_value}
  ```

  Use the `fromFile` form to load values from a JSON file:

  ```yaml momentic.config.yaml theme={null}
  environments:
    - name: dev
      envVariables:
        VAR_FROM_FILE:
          fromFile: package.json
          json: true
  ```
</ParamField>

<ParamField path="environments[].inheritFromShell" type="boolean">
  Include every variable from the enclosing shell at runtime. Default: `false`.

  ```yaml momentic.config.yaml theme={null}
  environments:
    - name: dev
      inheritFromShell: true
  ```
</ParamField>

<ParamField path="environments[].envFile" type="string">
  Path to a `.env`-format file to load. Each line is a `KEY=VALUE` pair; values
  become `env.VARIABLE_NAME`.

  ```yaml momentic.config.yaml theme={null}
  environments:
    - name: dev
      envFile: .dev.env
  ```
</ParamField>

<ParamField path="environments[].browser.proxy" type="{ server: string; username?: string; password?: string }">
  HTTP proxy configuration scoped to this environment. `server` must include
  the protocol (`http://` or `https://`), host, and port.

  ```yaml momentic.config.yaml theme={null}
  environments:
    - name: dev
      browser:
        proxy:
          server: http://proxy.internal.example.com:3128
          username: my-proxy-user
          password: my-proxy-password
  ```
</ParamField>

## Secrets

Keep passwords, API tokens, and other secrets out of `momentic.config.yaml` and
out of version control. Provide them at runtime through one of these - the
resolved values are still read in tests as `env.*`:

<Tabs>
  <Tab title=".env file">
    Point an environment at a `.env`-format file with
    [`envFile`](#environments-envfile) and keep that file out of git
    (`.gitignore`). Each `KEY=VALUE` line becomes `env.KEY`.

    ```yaml momentic.config.yaml theme={null}
    environments:
      - name: dev
        envFile: .secrets.env
    ```

    ```bash .secrets.env theme={null}
    PASSWORD=super-secret
    API_TOKEN=sk_live_...
    ```
  </Tab>

  <Tab title="Shell / CI secrets">
    Set the secret as an environment variable in your shell or CI secrets
    manager, then either inherit the whole shell with
    [`inheritFromShell`](#environments-inheritfromshell) or reference individual
    variables with [dotenvx interpolation](https://dotenvx.com/docs/env-file#interpolation)
    (`${SHELL_VAR}`).

    ```yaml momentic.config.yaml theme={null}
    environments:
      - name: ci
        inheritFromShell: true # pull every variable from the enclosing shell
      - name: dev
        envVariables:
          API_TOKEN: ${API_TOKEN} # read one variable from the shell
    ```

    This is the standard pattern in CI - store the value as a masked secret and
    expose it to the `momentic run` step. See the
    [CI/CD guides](/running-tests/ci/github-actions) for per-provider setup.
  </Tab>
</Tabs>

<Note>
  Your Momentic API key is a secret too. Export it as `MOMENTIC_API_KEY` rather
  than committing it - see [API keys](/account/api-keys-and-team#setting-a-key).
</Note>

For 2FA/TOTP secrets specifically, see
[Log in with OTPAuth](/guides/auth/otpauth).
