Overview
Getting environment variables is useful for:- Inspecting current environment configuration
- Verifying variables are set correctly
- Accessing system and custom variables
- Debugging environment-related issues
Environment variables include both system variables (like
PATH, HOME) and custom variables youβve set. Sensitive values may be masked in responses.Get All Environment Variables
Retrieve all environment variables:- Python
- JavaScript
Get Specific Variable
Get a single environment variable:- Python
- JavaScript
List All Variables
Iterate through all environment variables:- Python
- JavaScript
Filter Variables
Filter environment variables by prefix or pattern:- Python
- JavaScript
Check Variable Existence
Check if a variable exists:- Python
- JavaScript
Verify Variables in Code
Verify environment variables are accessible in code execution:- Python
- JavaScript
Complete Example
Hereβs a complete example showing environment variable retrieval:- Python
- JavaScript
Best Practices
1
1. Use get() for Single Variables
Use
env.get(key) for retrieving individual variables with optional defaults.2
2. Use get_all() for Multiple Variables
Use
env.get_all() when you need to access multiple variables or iterate through all.3
3. Handle Missing Variables
Always check if variables exist or provide defaults when retrieving.
4
4. Mask Sensitive Values
When displaying environment variables, mask sensitive values (keys, secrets, passwords, tokens).
5
5. Verify in Code
Test that environment variables are accessible in code execution to ensure theyβre set correctly.
Related
- Setting Environment Variables - Set environment variables
- Updating Environment Variables - Update variables
- SDK: sandbox.env.get() - Python SDK method
- API: GET /env - VM Agent API endpoint
- CLI Environment Variables - Environment variables from CLI
Next Steps
- Learn about Setting Environment Variables to configure your sandbox
- Explore Updating Environment Variables to modify existing variables
- Review Clearing Environment Variables to remove variables

