Overview
Environment variables allow you to configure your skills without hardcoding sensitive information like API keys.Using Environment Variables
Import the env Function
Setting Environment Variables
Quick Setup: Use
lua env command for an interactive interface to manage environment variables in both sandbox and production environments.1
System Environment
Variables from your system environment
2
.env File
Variables from
.env file in project root.env file overrides system environment variables. For production, use lua env command to manage variables on the server.Method 1: .env File (Recommended for Development)
Create a.env file in your project root:
.gitignore
.env.example
Create a.env.example file to document required variables:
.env.example to git, but never commit .env!
Method 2: Interactive Command
Use thelua env command for an interactive interface:
1
Run Command
2
Select Environment
Choose Sandbox (.env file) or Production (API)
3
Manage Variables
Add, update, delete, or view variables through interactive menu
4
Changes Saved
Variables are saved to
.env (sandbox) or API (production)Complete Guide
See full documentation for the
lua env commandExample: External API Integration
Stripe Payment Tool
.env File
Best Practices
✅ Do: Use descriptive names
✅ Do: Use descriptive names
✅ Do: Provide defaults for non-secrets
✅ Do: Provide defaults for non-secrets
✅ Do: Validate critical variables
✅ Do: Validate critical variables
✅ Do: Document required variables
✅ Do: Document required variables
Create
.env.example with all required variables and example values❌ Don't: Hardcode secrets
❌ Don't: Hardcode secrets
❌ Don't: Commit .env to git
❌ Don't: Commit .env to git
Always add
.env to .gitignore❌ Don't: Log sensitive values
❌ Don't: Log sensitive values
Common Patterns
Pattern: Required Variable
Pattern: Optional with Default
Pattern: Validation
Pattern: Environment-Specific Configuration
Testing with Environment Variables
In lua test
Environment variables are automatically loaded from.env when you run:
In lua chat
Environment variables are loaded based on selected mode:- Sandbox mode: Uses
.envfile - Production mode: Uses production variables from server
Troubleshooting
Variable not found
Variable not found
Problem:
env('MY_VAR') returns undefinedSolutions:- Check spelling in
.envfile - Ensure
.envis in project root - Restart
lua chatif running - For production, use
lua envto verify variables on server
Changes not taking effect
Changes not taking effect
Problem: Updated
.env but changes not visibleSolution: Restart the CLI command:Different values in dev vs production
Different values in dev vs production
Problem: Works locally but not when deployedSolution: Use
lua env to manage production variables:
