Skip to main content

Overview

The lua env command provides an interactive interface for managing environment variables in both sandbox (development) and production environments.
lua env                  # Interactive: choose environment
lua env sandbox          # Direct: manage .env file
lua env staging          # Direct: alias for sandbox
lua env production       # Direct: manage production API vars
New in v2.6.0: Direct environment access lets you skip the selection prompt for faster workflows!

Sandbox Mode

Manage .env file locally

Production Mode

Manage variables on server via API

Interactive Menu

Add, update, delete, and view variables

Secure

Values masked in list view

Usage Modes

Default behavior - prompts for environment
$ lua env
? Select environment:
  β€Ί πŸ”§ Sandbox (.env file)
    πŸš€ Production (API)
Best for: When you’re not sure which environment

Quick Start

1

Run Command

lua env sandbox        # Direct to sandbox
# or
lua env                # Interactive
2

Choose Environment (if interactive)

? Select environment:
  πŸ”§ Sandbox (.env file)
  πŸš€ Production (API)
3

Manage Variables

  • βž• Add new variable
  • ✏️ Update existing
  • πŸ—‘οΈ Delete variable
  • πŸ‘οΈ View full value

Environment Selection

Local DevelopmentManages your .env file in the project directory.
? Select environment: πŸ”§ Sandbox (.env file)
Features:
  • βœ… No authentication required
  • βœ… Instant changes
  • βœ… Local file management
  • βœ… Used by lua test and lua chat
File location: PROJECT_ROOT/.env

Actions Available

Add New Variable

? What would you like to do? βž• Add new variable
? Variable name: STRIPE_API_KEY
? Variable value: sk_test_abc123
πŸ”„ Saving...
βœ… Variable "STRIPE_API_KEY" added successfully
Variable name
string
required
Must start with letter/underscore, contain only letters, numbers, underscores
Variable value
string
required
Any string value (can include spaces, special characters)

Update Existing Variable

? What would you like to do? ✏️ Update existing variable
? Select variable to update: STRIPE_API_KEY
? New value for STRIPE_API_KEY: sk_test_xyz789
πŸ”„ Saving...
βœ… Variable "STRIPE_API_KEY" updated successfully

Delete Variable

? What would you like to do? πŸ—‘οΈ Delete variable
? Select variable to delete: OLD_KEY
? Are you sure you want to delete "OLD_KEY"? Yes
πŸ”„ Saving...
βœ… Variable "OLD_KEY" deleted successfully
Deletion requires confirmation to prevent accidents. Default is β€œNo”.

View Variable Value

? What would you like to do? πŸ‘οΈ View variable value
? Select variable to view: STRIPE_API_KEY
============================================================
Variable: STRIPE_API_KEY
============================================================
sk_test_abc123xyz789
============================================================

Press Enter to continue...
Shows the full unmasked value for copying.

Variable Display

Variables are masked for security in the list view:
============================================================
πŸ“‹ Environment Variables (Sandbox)
============================================================

1. DATABASE_URL = post**********************
2. STRIPE_KEY = sk-t**********************
3. API_SECRET = abc1**********************
Masking rules:
  • Shows first 4 characters
  • Replaces rest with asterisks (max 20)
  • Values < 4 chars show only asterisks

Variable Naming Rules

DATABASE_URL           βœ…
API_KEY                βœ…
STRIPE_SECRET_KEY      βœ…
MAX_CONNECTIONS        βœ…
enable_feature         βœ…
_INTERNAL_CONFIG       βœ…

Use in Development Workflow

Step 1: Configure Variables

# Set up sandbox environment variables
lua env sandbox
# Add: DATABASE_URL, API_KEY, STRIPE_SECRET, etc.

# Set up production environment variables
lua env production
# Add production API keys and URLs

Step 2: Test Locally

# Variables are automatically loaded
lua test

# Or test in conversation
lua chat

Step 3: Verify Production Config

# Check production variables before deploying
lua env production

Step 4: Deploy

lua push
lua deploy

Sandbox vs Production

Local Development
lua env  # β†’ Choose Sandbox
Add variables like:
DATABASE_URL=postgresql://localhost:5432/dev
STRIPE_KEY=sk_test_...
DEBUG=true
Used by:
  • lua test
  • lua chat (sandbox mode)
  • Local development

Best Practices

# Sandbox - Test keys
STRIPE_KEY=sk_test_abc123
DATABASE=dev_database

# Production - Live keys
STRIPE_KEY=sk_live_xyz789
DATABASE=prod_database
Add to .gitignore:
.env
.env.local
.env.*.local
Commit .env.example instead with placeholder values
Create .env.example:
# Required API Keys
STRIPE_KEY=sk_test_your_key_here
DATABASE_URL=postgresql://localhost:5432/dbname

# Optional
DEBUG=true
MAX_RETRIES=3
Update sensitive keys every 90 days:
  • API keys
  • Database passwords
  • JWT secrets
  • Encryption keys

Example Session

$ lua env sandbox
# Or interactive: lua env β†’ Choose Sandbox

============================================================
πŸ“‹ Environment Variables (Sandbox)
============================================================

ℹ️  No environment variables configured.

? What would you like to do? βž• Add new variable
? Variable name: DATABASE_URL
? Variable value: postgresql://localhost:5432/myapp
πŸ”„ Saving...
βœ… Variable "DATABASE_URL" added successfully

============================================================
πŸ“‹ Environment Variables (Sandbox)
============================================================

1. DATABASE_URL = post**********************

? What would you like to do? βž• Add new variable
? Variable name: STRIPE_KEY
? Variable value: sk_test_abc123
πŸ”„ Saving...
βœ… Variable "STRIPE_KEY" added successfully

============================================================
πŸ“‹ Environment Variables (Sandbox)
============================================================

1. DATABASE_URL = post**********************
2. STRIPE_KEY = sk-t**********************

? What would you like to do? ❌ Exit

πŸ‘‹ Goodbye!

Troubleshooting

Problem: Tool can’t find environment variableSolution:
import { env } from 'lua-cli';

const apiKey = env('STRIPE_KEY');
if (!apiKey) {
  throw new Error('STRIPE_KEY not configured. Run: lua env');
}
Error: EACCES: permission deniedSolution:
chmod 644 .env
Problem: Changes don’t persistSolutions:
  1. Verify API key: lua auth key
  2. Check network connection
  3. Try again
Error: Validation errorFix: Use valid format:
  • Start with letter or underscore
  • Only letters, numbers, underscores
  • No hyphens, spaces, or special characters

lua test

Uses sandbox environment variables

lua chat

Uses sandbox or production based on mode

lua push

Doesn’t include env vars (stored separately)

lua deploy

Uses production environment variables

Next Steps