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

# Environments

> Configure isolated deployment environments in Unkey to separate production traffic from preview and staging builds with scoped settings.

<Info>
  Deploying applications on Unkey is in public beta. To try it, open the product switcher in the
  top-left of the dashboard and select **Deploy**. During beta, deployed
  resources are free. We're eager for feedback, so let us know what you think
  on [Discord](https://unkey.com/discord), [X](https://x.com/unkeydev), or
  email [support@unkey.com](mailto:support@unkey.com).
</Info>

An environment is an isolated deployment target within an [app](/platform/apps/overview). Each environment has its own deployments, [variables](/platform/variables/overview), [custom domains](/networking/domains), and [gateway policies](/platform/gateway/overview).

## Production and preview

Every app gets two environments:

| Environment    | Purpose                              |
| -------------- | ------------------------------------ |
| **Production** | Serves live traffic.                 |
| **Preview**    | For testing branches before merging. |

Unkey creates both environments automatically when you create a project. You don't need to set them up manually.

<Note>
  Custom environments beyond production and preview are not yet available.
</Note>

## Branch mapping

When you connect a [GitHub repository](/build-and-deploy/github), Unkey maps branches to environments:

* Pushes to the default branch (typically `main`) deploy to **production**.
* Pushes to any other branch deploy to **preview**.

Each push creates a new [deployment](/build-and-deploy/deployments) in the corresponding environment.

## Environment-scoped configuration

Configuration is scoped per environment, so production and preview can differ:

* **Variables**: Different database URLs, API keys, and feature flags for each environment
* **Custom domains**: Production might use `api.acme.com` while preview uses auto-generated domains
* **Regions and instances**: Run production in multiple regions with higher instance counts, and preview in a single region
* **Gateway policies**: Apply stricter rate limits or authentication rules in production

## Sticky domains

Each environment has a sticky domain that always points to the latest deployment in that environment:

```text theme={"theme":"kanagawa-wave"}
<project>-<app>-<environment>-<workspace>.unkey.app
```

When a new deployment reaches the Ready state, the environment domain updates automatically. You don't need to reconfigure DNS or update your clients.

Production environments also get a live domain without the environment name:

```text theme={"theme":"kanagawa-wave"}
<project>-<app>-<workspace>.unkey.app
```

See [Wildcard domains](/networking/wildcard-domains) for the full domain naming pattern.

## Deployments per environment

An environment can have many deployments, but only one is active at a time.

In production, when a new deployment goes live, the previous one stops after 30 minutes. Stopped deployments are available for [rollbacks](/build-and-deploy/rollbacks), but take longer to serve traffic because their containers need to start again.

In preview environments, deployments stay running as long as they receive traffic. Idle preview deployments (zero requests for 1 hour) automatically stop to free up resources.

## Next steps

<CardGroup cols={2}>
  <Card title="Variables" icon="key" href="/platform/variables/overview">
    Configure environment-specific variables
  </Card>

  <Card title="Custom domains" icon="globe" href="/networking/domains">
    Serve your app from your own domain
  </Card>
</CardGroup>
