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

# crewship env

> Manage environment variables for your crew

## Overview

Environment variables let you configure your crew without changing code. Use them for:

* API keys (OpenAI, Anthropic, etc.)
* External service credentials
* Configuration that varies between environments

## Commands

### Set Variables

```bash theme={null}
crewship env set KEY=value
```

Set multiple variables at once:

```bash theme={null}
crewship env set OPENAI_API_KEY=sk-... ANTHROPIC_API_KEY=sk-ant-...
```

### Options

| Option             | Description                                    |
| ------------------ | ---------------------------------------------- |
| `--name`, `-n`     | Deployment name (for multi-deployment configs) |
| `--project <name>` | Target project (defaults to current directory) |

### List Variables

```bash theme={null}
crewship env list
```

Output:

```
Environment variables for my-crew:

  OPENAI_API_KEY     sk-...xxxx (set 2 days ago)
  ANTHROPIC_API_KEY  sk-ant-...xxxx (set 2 days ago)
  DEBUG_MODE         false (set 5 days ago)

3 variables
```

<Note>Values are masked for security. Only the first and last few characters are shown.</Note>

### Get a Variable

```bash theme={null}
crewship env get OPENAI_API_KEY
```

Shows the masked value:

```
OPENAI_API_KEY=sk-...xxxx
```

### Remove Variables

```bash theme={null}
crewship env rm VARIABLE_NAME
```

Remove multiple:

```bash theme={null}
crewship env rm VAR1 VAR2 VAR3
```

## Examples

### Setting API keys

```bash theme={null}
# OpenAI
crewship env set OPENAI_API_KEY=sk-proj-...

# Anthropic
crewship env set ANTHROPIC_API_KEY=sk-ant-...

# Serper (for web search)
crewship env set SERPER_API_KEY=...
```

### Configuration variables

```bash theme={null}
crewship env set LOG_LEVEL=debug
crewship env set MAX_RETRIES=3
```

### Multi-deployment projects

Target a specific named deployment:

```bash theme={null}
crewship env set --name research-agent OPENAI_API_KEY=sk-...
crewship env list --name writer-agent
```

### Using in your crew

Variables are automatically available as environment variables:

```python theme={null}
import os

openai_key = os.environ["OPENAI_API_KEY"]
log_level = os.environ.get("LOG_LEVEL", "info")
```

Or with CrewAI's built-in support:

```python theme={null}
from crewai import Agent, LLM

# CrewAI automatically uses OPENAI_API_KEY
agent = Agent(
    role="Researcher",
    llm=LLM(model="gpt-4o")
)
```

## Loading from .env

Load variables from a `.env` file:

```bash theme={null}
crewship env set --file .env
```

<Warning>Never commit `.env` files to version control. Add `.env` to your `.gitignore`.</Warning>

## Variable Scope

Environment variables are scoped to a **project**, not a deployment. This means:

* All deployments in a project share the same variables
* Updating a variable affects all future runs
* No redeploy is needed after changing variables

## Encryption

All environment variables are:

* Encrypted at rest using AES-256
* Transmitted over TLS
* Never logged or exposed in build output

## Reserved Variables

These variables are set by Crewship and cannot be overridden:

| Variable                 | Description           |
| ------------------------ | --------------------- |
| `CREWSHIP_RUN_ID`        | Current run ID        |
| `CREWSHIP_DEPLOYMENT_ID` | Current deployment ID |
| `CREWSHIP_PROJECT`       | Project name          |

## Best Practices

<AccordionGroup>
  <Accordion title="Use descriptive names">
    Name variables clearly: `OPENAI_API_KEY` not `KEY1`
  </Accordion>

  <Accordion title="Separate environments">
    Use different projects for staging and production
  </Accordion>

  <Accordion title="Rotate secrets regularly">Update API keys periodically for security</Accordion>

  <Accordion title="Don't hardcode fallbacks">
    Fail fast if a required variable is missing instead of using default values for secrets
  </Accordion>
</AccordionGroup>

## Related

<CardGroup cols={2}>
  <Card title="Configuration" icon="gear" href="/configuration/crewship-toml">
    Project configuration
  </Card>

  <Card title="Deploy" icon="rocket" href="/cli/deploy">
    Deploy your crew
  </Card>
</CardGroup>
