# Environment Variables

By default, mirrord imports all environment variables from the remote pod into your local process. This means your local code automatically gets the same database URLs, API keys, feature flags, and service discovery values as the deployed application, without any manual setup.

Local environment variables that aren't present in the remote pod are preserved. When a variable exists in both, the remote value wins.

### Including only specific variables

If you only need a few remote variables (e.g. a database connection string), use `include` to allowlist them:

```json
{
  "feature": {
    "env": {
      "include": "DATABASE_URL;API_KEY;REDIS_HOST"
    }
  }
}
```

Variables are separated by semicolons. Supports regex patterns: `"include": "DB_.*"`.

### Excluding specific variables

If most remote variables are useful but a few cause problems locally, use `exclude`:

```json
{
  "feature": {
    "env": {
      "exclude": "PATH;HOME;USER;SHELL"
    }
  }
}
```

`include` and `exclude` are mutually exclusive. Use one or the other.

### Overriding values

Sometimes you want the remote variable but with a different value. For example, pointing at a local database while keeping everything else remote:

```json
{
  "feature": {
    "env": {
      "override": {
        "DATABASE_URL": "postgres://localhost:5432/mydb",
        "DEBUG": "true"
      }
    }
  }
}
```

Overrides are applied after remote variables are loaded, so they take priority over both remote and local values.

### Loading from a file

You can load overrides from a dotenv-style file:

```json
{
  "feature": {
    "env": {
      "env_file": ".env.local"
    }
  }
}
```

### Mapping variable names

If your local code expects a different variable name than what the remote pod uses:

```json
{
  "feature": {
    "env": {
      "mapping": {
        "REMOTE_DB_URL": "DATABASE_URL"
      }
    }
  }
}
```

This maps the remote `REMOTE_DB_URL` value into the local `DATABASE_URL` variable.

### Unsetting variables

To ensure a remote variable is *not* present in your local process at all:

```json
{
  "feature": {
    "env": {
      "unset": "KUBERNETES_SERVICE_HOST;KUBERNETES_PORT"
    }
  }
}
```

### Common scenarios

**"My app connects to the wrong database locally"** The remote `DATABASE_URL` is being imported. Either override it with a local value, or exclude it.

**"I need remote env vars but PATH keeps getting overwritten"** Exclude `PATH` (and other shell variables like `HOME`, `USER`, `SHELL`).

**"I want to test with a feature flag enabled"** Use `override` to set the flag value, regardless of what the remote pod has.

For the full list of environment variable settings, see the [configuration reference](https://metalbear.com/mirrord/docs/config#feature.env). For a technical explanation of how environment variables work under the hood, see the [Environment Variables reference](/mirrord/docs/reference/env.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://metalbear.com/mirrord/docs/using-mirrord/environment-variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
