Executor
CodeExecutionContainer
CodeExecutionContainer(tag: str, env: dict[str, str] | None = None, port: int | None = None, show_pull_progress: bool = True, workspace_path: Path | str | None = None)
Bases: ExecutionContainer
Context manager for managing code execution container lifecycle.
Extends ipybox
's ExecutionContainer
to provide workspace-specific bind mounts for skill directories.
Handles creation, port mapping, volume binding, and cleanup of the container.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tag
|
str
|
Docker image tag to use for the container |
required |
env
|
dict[str, str] | None
|
Optional environment variables to set in the container |
None
|
port
|
int | None
|
Optional host port to map to container's executor port. Random port used if not specified |
None
|
show_pull_progress
|
bool
|
Whether to show progress when pulling the Docker image. |
True
|
workspace_path
|
Path | str | None
|
Optional path to workspace directory, defaults to "workspace" |
None
|
Example
Source code in freeact/executor.py
CodeExecutionEnvironment
dataclass
CodeExecutionEnvironment(container: CodeExecutionContainer, executor: CodeExecutor, logger: Logger)
A convenience class that bundles the container, executor and logger of an execution environment.
Attributes:
Name | Type | Description |
---|---|---|
container |
CodeExecutionContainer
|
Manages a Docker container of the execution environment |
executor |
CodeExecutor
|
Manages an IPython kernel running in the container |
logger |
Logger
|
Logger instance for recording model interactions |
CodeExecutor
Bases: ExecutionClient
Context manager for executing code in an IPython kernel running in a CodeExecutionContainer
.
Provides stateful code execution within a container, maintaining kernel state between executions. Manages scoped skill and image storage directories.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Scope identifier used to:
|
required |
workspace
|
Workspace
|
a |
required |
*args
|
Additional arguments passed to the |
()
|
|
**kwargs
|
Additional keyword arguments passed to the |
{}
|
Example
Source code in freeact/executor.py
Workspace
dataclass
Workspace(path: Path)
Represents a workspace containing shared and private agent skills. These are skills that are not pre-installed in the code execution container.
Workspaces are bind-mounted into CodeExecutionContainer
to share skills between
a code execution container and the host machine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
Base path of the workspace directory structure on the host. |
required |
dotenv_variables
dotenv_variables(dotenv_path: Path | None = Path('.env'), export: bool = True, **kwargs) -> Dict[str, str]
Load environment variables from a .env
file.
Reads environment variables from a .env
file and optionally exports them to os.environ
.
If no path is provided, searches for a .env
file in parent directories.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dotenv_path
|
Path | None
|
Path to the |
Path('.env')
|
export
|
bool
|
Whether to export variables to current environment. Defaults to |
True
|
**kwargs
|
Additional keyword arguments passed to |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, str]
|
Dictionary mapping environment variable names to their values. |
Source code in freeact/executor.py
execution_environment
async
execution_environment(executor_key: str = 'default', ipybox_tag: str = 'ghcr.io/gradion-ai/ipybox:minimal', env_vars: dict[str, str] = dotenv_variables(), workspace_path: Path | str = Path('workspace'), log_file: Path | str = Path('logs', 'agent.log'))
Convenience context manager for a local, sandboxed code execution environment.
Sets up a complete environment for executing code securely on the local machine, including:
- A Docker container based on
ipybox
- A code executor connected to the container
- A logger for recording model interactions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
executor_key
|
str
|
CodeExecutor key for private workspace directories |
'default'
|
ipybox_tag
|
str
|
Tag of the |
'ghcr.io/gradion-ai/ipybox:minimal'
|
env_vars
|
dict[str, str]
|
Environment variables to pass to the container |
dotenv_variables()
|
workspace_path
|
Path | str
|
Path to workspace directory on host machine |
Path('workspace')
|
log_file
|
Path | str
|
Path to log file for recording model interactions |
Path('logs', 'agent.log')
|