Overview
Updating environment variables is ideal for:- Adding new variables without removing existing ones
- Updating specific variables while preserving others
- Incrementally building environment configuration
- Modifying configuration without full replacement
update() merges new variables with existing ones. Existing variables not specified in the update are preserved. This is safer than set_all() which replaces everything.Update Single Variable
Update a single environment variable:- Python
- JavaScript
Update Multiple Variables
Update multiple variables at once:- Python
- JavaScript
Incremental Configuration
Build environment configuration incrementally:- Python
- JavaScript
Override Existing Variables
Update existing variables with new values:- Python
- JavaScript
Complete Example
Hereβs a complete example showing incremental environment setup:- Python
- JavaScript
Best Practices
1
1. Use update() Instead of set_all()
Prefer
update() over set_all() to preserve existing variables unless you want to replace everything.2
2. Build Incrementally
Build environment configuration incrementally by updating variables in logical groups.
3
3. Override When Needed
Use
update() to override existing variables with new values without affecting others.4
4. Group Related Variables
Update related variables together (e.g., all API config, all database config) for better organization.
5
5. Verify After Updates
Always verify variables are updated correctly using
get_all() after updates.Related
- Getting Environment Variables - Retrieve environment variables
- Setting Environment Variables - Set or replace variables
- SDK: sandbox.env.update() - Python SDK method
- API: PATCH /env - VM Agent API endpoint
- CLI Environment Variables - Environment variables from CLI
Next Steps
- Learn about Getting Environment Variables to retrieve variables
- Explore Setting Environment Variables to replace all variables
- Review Clearing Environment Variables to remove variables

