What Are Environment Variables? Configuration Without Code
Environment variables configure your app at runtime. Learn how OpenClaw uses them and how to set them safely.
Environment variables (env vars) are key-value pairs that configure your application at runtime. Instead of hardcoding a database URL or API key in your source code, you set it as an environment variable that gets injected at startup.
How OpenClaw Uses Them
OpenClaw's config is defined in openclaw.json, but the values can reference environment variables. This lets you keep secrets out of your config file. For example: "apiKey": "${TELEGRAM_BOT_TOKEN}" references the TELEGRAM_BOT_TOKEN env var.
Setting Environment Variables on Fly
fly secrets set TELEGRAM_BOT_TOKEN=your_token_here
fly secrets set OPENAI_API_KEY=sk-...
Secrets are encrypted at rest and injected into your running VMs without being stored in your config file or Git history.
.env Files
For local development, use a .env file (never commit it to Git). Tools like direnv or dotenv load these automatically. OpenClaw respects standard Node.js dotenv behavior.
Best Practices
Never commit secrets to Git. Use fly secrets for production. Use .env.example (without values) to document required variables.