AsyncEnv API Reference
April 9, 2026 ยท View on GitHub
Overview
The Env module provides methods for setting and querying global environment variables within a session sandbox. Variables set via this module persist across all MCP tools (shell, code interpreter, etc.) within the session.
AsyncEnv
class AsyncEnv(AsyncBaseService)
Async environment variable management service for AgentBay sessions.
Provides methods to set and get global environment variables that persist across all MCP tools (shell, code interpreter, etc.) within a session.
init
def __init__(self, session)
set
async def set(envs: Dict[str, str]) -> BoolResult
Set or update global environment variables in the session sandbox.
Existing keys are overwritten; new keys are added. Variables become visible to all subsequent MCP tool invocations (shell, code interpreter, etc.).
Arguments:
envs: Dictionary of environment variable key-value pairs.
Both keys and values must be strings. Must not be empty.
Returns:
BoolResult: Result with success=True if variables were set successfully.
Raises:
ValueError: If envs is empty or contains non-string keys/values.
get
async def get(keys: Optional[List[str]] = None) -> EnvResult
Get global environment variables from the session sandbox.
Arguments:
keys: Optional list of specific variable names to retrieve.
If None or empty, returns all environment variables.
Returns:
EnvResult: Result containing envs dict with variable key-value pairs.
Best Practices
- Use env.set to configure variables before running shell commands or code
- Both keys and values must be strings
- Setting a key that already exists will overwrite the previous value
- Use env.get with specific keys to reduce response size
See Also
Related APIs:
Documentation generated automatically from source code using pydoc-markdown.