Last Verified: 2025-01-27
Package:
hopx-ai on PyPI
Overview
TheEnvironmentVariables resource (accessed via sandbox.env) provides methods for managing environment variables in sandboxes. Use this resource to set, get, update, and delete environment variables that are available to all code execution and commands.
Environment variables set through this resource persist for the lifetime of the sandbox and are available to all executions.
Access
Methods
get_all
Get all environment variables.
Dict[str, str] - Dictionary of all environment variables
Example:
get
Get a specific environment variable value.
key(str): Environment variable namedefault(str, optional): Default value if not found
Optional[str] - Variable value or default
Example:
set
Set a single environment variable.
key(str): Environment variable namevalue(str): Variable valuetimeout(int, optional): Request timeout
Dict[str, str] - Updated dictionary of all environment variables
Example:
set_all
Set/replace all environment variables (destructive).
env_vars(Dict[str, str]): Dictionary of environment variablestimeout(int, optional): Request timeout
Dict[str, str] - Updated dictionary of all environment variables
Example:
update
Update specific environment variables (merge with existing).
env_vars(Dict[str, str]): Dictionary of environment variables to updatetimeout(int, optional): Request timeout
Dict[str, str] - Updated dictionary of all environment variables
Example:
delete
Delete a specific environment variable.
key(str): Environment variable name to deletetimeout(int, optional): Request timeout
Examples
Example 1: Basic Environment Variable Management
Example 2: Setting Variables at Creation
Example 3: Updating Variables
Example 4: Using Variables in Code Execution
Example 5: Using Variables in Commands
Related Classes
See Also
- Core Concepts: Environment Variables - Learn about environment configuration
- Sandbox Class - Access env via
sandbox.env
Related
- Getting Environment Variables - Learn about getting env vars
- Setting Environment Variables - Learn about setting env vars
- Updating Environment Variables - Batch update env vars
- API: GET /env - VM Agent API endpoint
Next Steps
- Learn about Getting Environment Variables to read values
- Explore Setting Environment Variables to configure environment
- Review Updating Environment Variables for batch updates
- CLI Environment Variables - Manage environment variables from the command line
Related
- Getting Environment Variables - Learn about retrieving variables
- Setting Environment Variables - Learn about setting variables
- Updating Environment Variables - Learn about updating variables
- API: Environment Variables - VM Agent API endpoints

