Skip to main content

Overview

Environment variables allow you to configure your skills without hardcoding sensitive information like API keys.
Never hardcode secrets in your code! Always use environment variables.

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.
There are two ways to set environment variables, loaded in this priority order:
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.
Create a .env file in your project root:

.gitignore

Always add .env to .gitignore!

.env.example

Create a .env.example file to document required variables:
Commit .env.example to git, but never commit .env!

Method 2: Interactive Command

Use the lua 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 command

Example: External API Integration

Stripe Payment Tool

.env File

Best Practices

Create .env.example with all required variables and example values
Always add .env to .gitignore

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 .env file
  • Production mode: Uses production variables from server

Troubleshooting

Problem: env('MY_VAR') returns undefinedSolutions:
  1. Check spelling in .env file
  2. Ensure .env is in project root
  3. Restart lua chat if running
  4. For production, use lua env to verify variables on server
Problem: Updated .env but changes not visibleSolution: Restart the CLI command:
Problem: Works locally but not when deployedSolution: Use lua env to manage production variables:

Example Project Structure

Next Steps

Build Your First Skill

Use environment variables in a real project

Tool Examples

See payment integration example