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

# Environments

> Organize apps and manage environment-specific configuration

Environments help you organize your apps by deployment stage (Dev, Staging, Production) and manage environment-specific configuration through environment variables.

## What are Environments?

An **Environment** in Autosana serves two purposes:

1. **App Organization**: Group apps by deployment stage or purpose
2. **Configuration Management**: Store environment-specific variables (API keys, URLs, credentials)

## Creating an Environment

### Step 1: Navigate to Settings

Click your profile icon or navigate to **[Settings](https://autosana.ai/settings)** from the sidebar.

### Step 2: Find the Environments Section

Scroll down to the **Environments** section.

### Step 3: Create Environment

1. Click **Create Environment**
2. Enter a name (e.g., "Development", "Staging", "Production")
3. Click **Create**

Your new environment appears in the list.

## Duplicating an Environment

If you already have an environment with many variables configured, you can duplicate it to quickly create a new one with the same settings.

### Step 1: Find the Source Environment

In the Environments section, locate the environment you want to duplicate.

### Step 2: Click Duplicate

Hover over the environment and click the **copy icon** that appears.

### Step 3: Configure the New Environment

1. Enter a name for the new environment (defaults to "\[Original Name] (copy)")
2. Review the list of variables that will be copied
3. Optionally edit any values before saving
4. Toggle off any variables you don't want to include
5. Click **Duplicate**

All selected variables (including secrets) are copied to the new environment.

<Tip>
  Use duplicate when setting up similar environments, like creating a "Sandbox" from an existing "Staging" configuration.
</Tip>

## Managing Environment Variables

Environment variables are key-value pairs that you can reference in hooks and flow instructions. They make your flows and hooks reusable across different environments.

### Adding a Variable

1. Find your environment in the Environments section
2. Click **Add Variable** or the **+** icon
3. Enter the **Key** (e.g., `TEST_EMAIL`)
4. Enter the **Value** (e.g., `test@staging.com`)
5. Click **Save** or press Enter

<Tip>
  Use UPPERCASE\_WITH\_UNDERSCORES for variable names (e.g., `API_KEY`, `TEST_PASSWORD`) to make them easily identifiable.
</Tip>

### Editing a Variable

1. Find the variable in the environment
2. Click the pencil icon (✏️)
3. Update the key or value
4. Save changes

### Deleting a Variable

1. Find the variable in the environment
2. Click the trash icon (🗑️)
3. Confirm deletion

<Warning>
  Deleting a variable will cause any hooks or flows that reference it to fail if they try to use `${env:VARIABLE_NAME}`.
</Warning>

## Using Environment Variables

### In Hooks

Reference variables using `${env:VARIABLE_NAME}` syntax:

```
curl -X POST ${env:API_BASE_URL}/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"${env:TEST_EMAIL}","password":"${env:TEST_PASSWORD}"}'
```

For scripts (Python, JS, Bash), environment variables are injected automatically and accessed via your language's standard method (e.g., `os.environ.get('TEST_EMAIL')` in Python).

[Learn more about using variables in hooks →](/hooks#environment-variables-in-hooks)

### In Flow Instructions

<iframe src="https://www.veed.io/embed/db91d667-c491-409e-b421-ac32add7f498?watermark=0&color=default&sharing=0&title=1" width="744" height="504" frameBorder="0" title="Adding Variables to Flows" allow="fullscreen" allowFullScreen />

You can also use variables directly in flow instructions:

```
Open the app
Navigate to Settings
Enter "${env:API_KEY}" in the API Key field
Tap Save
```

### Variable Scope

Variables are scoped to their environment:

* Apps assigned to "Staging" environment use Staging variables
* Apps assigned to "Production" environment use Production variables
* Apps without an environment don't have access to variables

<Note>
  The `${env:KEY}` syntax also resolves runtime variables — suite variables, flow variables, hook exports, and values set by the agent — in addition to environment variables. Runtime variables take precedence over environment variables when they share the same key. See [Variables](/variables) for details on runtime variables, precedence, and dynamic agent variables.
</Note>

## Assigning Apps to Environments

### During App Creation

When creating a new app:

1. Select an environment from the **Environment** dropdown
2. Complete the app creation process

### For Existing Apps

1. Navigate to the **[Apps](https://autosana.ai/apps)** page
2. Find your app
3. Click the **Environment** dropdown on the app card
4. Select an environment

## Use Cases

### Development vs Production Credentials

**Development Environment:**

```
TEST_EMAIL = dev-user@example.com
TEST_PASSWORD = DevPass123
API_URL = https://api.dev.example.com
```

**Production Environment:**

```
TEST_EMAIL = prod-user@example.com
TEST_PASSWORD = ProdPass123
API_URL = https://api.example.com
```

**Flow (works in both):**

```
Log in with ${env:TEST_EMAIL} and ${env:TEST_PASSWORD}
Verify API connection to ${env:API_URL}
```

### Feature Flags

**Staging Environment:**

```
FEATURE_NEW_CHECKOUT = true
FEATURE_BETA_UI = true
EXPERIMENTAL_MODE = enabled
```

**Production Environment:**

```
FEATURE_NEW_CHECKOUT = false
FEATURE_BETA_UI = false
EXPERIMENTAL_MODE = disabled
```

**Flow (works in both):**

```
Open settings
Enable experimental mode if ${env:EXPERIMENTAL_MODE} is "enabled"
Verify new checkout is ${env:FEATURE_NEW_CHECKOUT}
```

## Best Practices

<Tip>
  **Use Consistent Naming**

  Establish a naming convention and stick to it:

  * `TEST_EMAIL`, `TEST_PASSWORD` for credentials
  * `API_URL`, `BASE_URL` for endpoints
  * `FEATURE_*` for feature flags
  * `ENV_*` for environment-specific settings
</Tip>

<Tip>
  **Use Variables for Anything That Changes**

  Not just credentials! Use variables for:

  * URLs and endpoints
  * Test data (names, addresses, etc.)
  * Configuration values
  * Feature flags
</Tip>

## Troubleshooting

### Variable Not Replacing in Hook

**Possible Causes:**

* Variable name doesn't match exactly (case-sensitive)
* Typo in variable name
* Wrong syntax (must be `${env:VAR_NAME}`)
* App not assigned to the environment

**Solutions:**

* Check variable name spelling and case
* Use `${env:VARIABLE}` — not `{{VARIABLE}}` or `$VARIABLE`
* Verify app is assigned to the correct environment

### Flow Works in One Environment but Not Another

**Cause:** Missing or different variables

**Solution:**

* Check that all required variables exist in both environments

## Managing Env Vars via API

Environment variables can be created, rotated, and deleted programmatically via the [Environment Variables API](/api-env-vars). Plaintext values come back in full; secret values are returned as `"***"` (write-only through the API).

## Next Steps

* [Use variables in hooks →](/hooks#using-environment-variables-in-hooks)
* [Organize apps by environment →](/apps#organizing-with-environments)
* [Create reusable hooks →](/hooks)
* [Manage env vars via API →](/api-env-vars)
