Workflows
Environment Variables
Managing environment variables in Sample Workflows
Overview
Environment variables in Sample Workflows provide a secure way to manage configuration values, API keys, and other sensitive data that your workflow needs to access. These variables are injected at deploy time and are only available within your workflow code.
How Environment Variables Work
Deployment-Time Injection
Environment variables are injected into your workflow when it’s deployed to the Sample platform. This means:
- They become available to your workflow code after deployment
- Changes to environment variables require a new deployment to take effect
Accessing Environment Variables
In your workflow code, you can access environment variables using Python’s built-in os.getenv()
function:
Best Practices
Security Considerations
- Never hardcode sensitive values in your workflow code
- Use environment variables for API keys, tokens, and connection strings
- Set appropriate access controls for who can view and modify environment variables
Naming Conventions
- Use UPPERCASE with underscores for environment variable names
- Be descriptive but concise:
DATABASE_URL
,STRIPE_API_KEY
- Group related variables with prefixes:
AWS_ACCESS_KEY
,AWS_SECRET_KEY
Default Values
Always provide sensible defaults when possible:
Common Use Cases
API Integration
Database Connections
Feature Flags
This allows your workflow code to remain the same across environments while adapting to different configurations.
Important Notes
- Environment variables are only available in workflow code, not in screen components
- Changes to environment variables require redeployment to take effect
- Environment variables are scoped to the specific workflow and environment
- Use the Sample platform’s environment variable management interface to set and update values securely