DockerPythonEnvironment - AG2
DockerPythonEnvironment
autogen.environments.docker_python_environment.DockerPythonEnvironment
DockerPythonEnvironment(image='python:3.11-slim', container_name_prefix='ag2_docker_env_', volumes=None, environment=None, network=None, pip_packages=None, requirements_file=None, dockerfile=None, build_args=None, cleanup_container=True, keep_container_running=False, container_startup_timeout=30)
Bases: PythonEnvironment
A Python environment using Docker containers for isolated execution.
Initialize a Docker Python environment.
| PARAMETER | DESCRIPTION |
|---|---|
image |
Docker image to use (ignored if dockerfile is provided) TYPE: strDEFAULT:'python:3.11-slim' |
container_name_prefix |
Prefix for container names TYPE: strDEFAULT:'ag2_docker_env_' |
volumes |
Dictionary mapping host paths to container paths for mounting TYPE:`dict[str, str] |
environment |
Dictionary of environment variables to set in the container TYPE:`dict[str, str] |
network |
Docker network to attach the container to TYPE:`str |
pip_packages |
List of pip packages to install in the container TYPE:`list[str] |
requirements_file |
Path to requirements.txt file to install in the container TYPE:`str |
dockerfile |
Optional path to a Dockerfile to build and use instead of pulling an image TYPE:`str |
build_args |
Optional build arguments for the Dockerfile TYPE:`dict[str, str] |
cleanup_container |
Whether to remove the container after use TYPE: boolDEFAULT:True |
keep_container_running |
Whether to keep the container running after execution TYPE: boolDEFAULT:False |
container_startup_timeout |
Timeout in seconds for container startup TYPE: intDEFAULT:30 |
get_executable
def get_executable()
Get the path to the Python executable in the Docker container.
execute_code
execute_code(code, script_path, timeout=30)
Execute code in the Docker container.
get_current_python_environment
get_current_python_environment(python_environment=None)
Get the current Python environment or the specified one if provided.
| PARAMETER | DESCRIPTION |
|---|---|
python_environment |
Optional environment to return if specified. TYPE: Optional[PythonEnvironment]DEFAULT:None |
| RETURNS | DESCRIPTION |
|---|---|
Optional[PythonEnvironment] |
The current Python environment or None if none is active. |