Sandbox
Environment Variables
Inject environment variables into sandboxes at creation time.
Overview
You can inject environment variables into a sandbox when creating it. These variables are available to all processes running inside the sandbox, making it easy to pass API keys, configuration values, and other runtime parameters.
Setting Environment Variables
Pass an envVars map (string to string) when creating a sandbox:
const sandbox = await client.createSandbox({
templateID: "python",
envVars: {
OPENAI_API_KEY: "sk-...",
DATABASE_URL: "postgresql://user:pass@host:5432/db",
NODE_ENV: "production",
},
});curl -X POST https://api.lelantos.ai/sandboxes \
-H "X-API-Key: lel_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"templateID": "python",
"envVars": {
"OPENAI_API_KEY": "sk-...",
"DATABASE_URL": "postgresql://user:pass@host:5432/db",
"NODE_ENV": "production"
}
}'Accessing Environment Variables
Inside the sandbox, environment variables are available through the standard OS mechanisms:
# In a shell command
echo $OPENAI_API_KEY
# In Python
import os
api_key = os.environ["OPENAI_API_KEY"]
# In Node.js
const apiKey = process.env.OPENAI_API_KEY;Best Practices
- Secrets management: Pass API keys and credentials via
envVarsrather than baking them into templates. This keeps your templates reusable and avoids storing secrets in images. - Configuration: Use environment variables for any values that change between sandbox instances (endpoints, feature flags, runtime modes).
- Naming: Use
UPPER_SNAKE_CASEfor environment variable names, following standard convention.
Environment variables are set at sandbox creation time and cannot be modified after the sandbox is running. If you need to change a value, create a new sandbox.