Environment Variables: Configuration Management
Store and manage configuration values for your OpenClaw agent using environment variables that keep sensitive data out of prompts and code.
What You Will Get
By the end of this guide, your OpenClaw agent will use environment variables to manage configuration settings like API URLs, feature flags, and behavioral parameters. You will be able to change the agent's behavior without editing prompts or redeploying.
Environment variables separate configuration from logic. Instead of hardcoding values in system prompts, you reference variables that can be updated independently. This makes it easy to maintain different configurations for staging and production, toggle features on or off, and update settings without touching the agent's core prompt.
You will create environment variables, reference them in prompts and tools, set up environment-specific overrides, and manage secrets securely. The result is a cleanly configured agent that is easy to maintain and safe to operate across multiple environments.
Step-by-Step Setup
Follow these steps to configure environment variables.
Open the Configuration Panel
Navigate to your agent's settings in the RunTheAgent dashboard and select the Environment Variables tab. This panel lists all existing variables with their values and scope. New agents start with a set of default system variables.
Create Your First Variable
Click Add Variable and enter a name, value, and description. Use uppercase names with underscores for readability, like MAX_RESPONSE_LENGTH or SUPPORT_EMAIL. The description helps your team understand what the variable controls.
Reference Variables in Prompts
Use the variable syntax in your agent's system prompt to inject configuration values dynamically. For example, 'Limit your responses to {{MAX_RESPONSE_LENGTH}} characters.' When the agent processes the prompt, the variable is replaced with its current value.
Set Up Environment-Specific Overrides
If you run separate staging and production instances, create environment-specific overrides. The same variable can have different values in each environment. For example, DEBUG_MODE might be 'true' in staging and 'false' in production.
Mark Sensitive Variables as Secrets
For variables that contain sensitive data like API keys or passwords, toggle the secret flag. Secret variables are encrypted at rest, masked in the dashboard, and never included in logs. They can only be read by the agent at runtime.
Use Variables in Tool Configurations
Reference environment variables in your tool configurations. For example, a webhook tool can use {{WEBHOOK_URL}} as its destination, and a database tool can use {{DB_CONNECTION_STRING}} for its connection. This keeps sensitive URLs and credentials out of the tool definition itself.
Audit and Clean Up Regularly
Review your environment variables periodically. Remove unused variables, update stale values, and verify that secrets are still valid. The configuration panel shows when each variable was last modified to help you identify candidates for cleanup.
Tips and Best Practices
Use Consistent Naming Conventions
Adopt a naming scheme like PREFIX_CATEGORY_NAME. For example, APP_SUPPORT_EMAIL and APP_MAX_TOKENS. Consistent naming makes it easy to find and group related variables.
Document Every Variable
Fill in the description field for every variable. Future team members will thank you when they can understand what RETRY_BACKOFF_MS controls without digging through prompts and tool configurations.
Do Not Hardcode Anything That Might Change
If a value could change between environments or over time, make it a variable. This includes URLs, thresholds, feature flags, and email addresses. The small upfront effort saves significant maintenance time later.
Rotate Secrets on a Schedule
Set reminders to rotate secret variables like API keys and passwords regularly. The configuration panel supports updating secret values without downtime, so rotations are seamless.
Frequently Asked Questions
Related Pages
Ready to get started?
Deploy your own OpenClaw instance in under 60 seconds. No VPS, no Docker, no SSH. Just your personal AI assistant, ready to work.
Starting at $24.50/mo. Everything included. 3-day money-back guarantee.