Skip to main content
Version: 0.3.0
Last Verified: 2025-01-27
Package: hopx-ai on PyPI

Overview

The EnvironmentVariables 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.
Returns: Dict[str, str] - Dictionary of all environment variables Example:
Expected Output:
See Also:

get

Get a specific environment variable value.
Parameters:
  • key (str): Environment variable name
  • default (str, optional): Default value if not found
Returns: Optional[str] - Variable value or default Example:
Expected Output:
See Also:

set

Set a single environment variable.
Parameters:
  • key (str): Environment variable name
  • value (str): Variable value
  • timeout (int, optional): Request timeout
Returns: Dict[str, str] - Updated dictionary of all environment variables Example:
Expected Output:
See Also:

set_all

Set/replace all environment variables (destructive).
Parameters:
  • env_vars (Dict[str, str]): Dictionary of environment variables
  • timeout (int, optional): Request timeout
Returns: Dict[str, str] - Updated dictionary of all environment variables
This replaces ALL existing environment variables. Use update() to merge instead.
Example:
Expected Output:

update

Update specific environment variables (merge with existing).
Parameters:
  • env_vars (Dict[str, str]): Dictionary of environment variables to update
  • timeout (int, optional): Request timeout
Returns: Dict[str, str] - Updated dictionary of all environment variables Example:
Expected Output:
See Also:

delete

Delete a specific environment variable.
Parameters:
  • key (str): Environment variable name to delete
  • timeout (int, optional): Request timeout
Example:
Expected Output:

Examples

Example 1: Basic Environment Variable Management

Expected Output:

Example 2: Setting Variables at Creation

Expected Output:

Example 3: Updating Variables

Expected Output:

Example 4: Using Variables in Code Execution

Expected Output:

Example 5: Using Variables in Commands

Expected Output:

  • Sandbox - Main sandbox class
  • Commands - Command execution resource
  • Files - File operations resource

See Also

Next Steps