Overview
utils/docker_utils.py provides a thin layer over the Docker SDK for Python to manage the lifecycle of evaluation containers and transfer files between the host and container.
Containers are used to provide reproducible, isolated environments for running agent-generated code. Each container mounts the HyperAgents repository directory as a read-write volume at /{REPO_NAME} (default: /hyperagents).
Logging
setup_logger
Creates a thread-safe file logger. Because evaluations can run in parallel threads, each thread maintains its own logger in thread-local storage.
Signature
Parameters
Absolute or relative path to the log file. The file is created or appended to.
Return Value
A
logging.Logger instance configured with:- Level:
INFO - Handler:
FileHandlerwith a thread-safeLockon its stream - Format:
%(asctime)s - %(threadName)s - %(levelname)s - %(message)s
get_thread_logger().Container Lifecycle
build_container
Builds a Docker image (if needed) and starts a new named container from it. The container is started in detached mode and kept alive with tail -f /dev/null.
Signature
Parameters
An initialised Docker client, typically from
docker.from_env().Path to the directory containing the
Dockerfile. Also mounted as a volume inside the container at /{REPO_NAME}.Tag for the Docker image to build or reuse.
Name for the new container. Any existing container with this name is forcibly removed before starting.
When
True, rebuilds the image from scratch even if a tag with image_name already exists (nocache=True).List of domain names active in this run. If any domain contains
"genesis", GPU passthrough is attempted. Supports both Docker (via device_requests) and Podman (via CDI nvidia.com/gpu=all).Whether to emit build and startup progress to the thread-local logger.
Return Value
The running container object, or
None if image build or container startup failed.cleanup_container
Stops and removes a container gracefully.
Signature
Parameters
A Docker container object to stop and remove.
Whether to log stop/remove progress and any errors.
File Transfer
copy_to_container
Copies a file or directory from the local filesystem into a running container using an in-memory tar archive.
Signature
Parameters
Target running container.
Local path to the file or directory to copy. Raises
FileNotFoundError if it does not exist.Destination path inside the container. The parent directory is created with
mkdir -p if it does not exist. For a file, dest_path.name becomes the archive entry name; for a directory, dest_path.name becomes the top-level directory name in the archive.Whether to log the copy result.
Return Value
None. Raises an exception on failure.
copy_from_container
Copies a file or directory from a running container to the local filesystem.
Signature
Parameters
Source running container.
Path inside the container to copy. Raises
FileNotFoundError if it does not exist in the container.Local destination path. Parent directories are created automatically.
Whether to log the copy result and errors.
Return Value
None. Raises an exception on failure.
Execution Output
log_container_output
Logs the output of a container.exec_run(...) call and raises an exception if the command exited with a non-zero exit code.
Signature
Parameters
The object returned by
container.exec_run(...). Expected to have .output (bytes or iterator of bytes) and .exit_code (int or None) attributes.When
False, all logging is suppressed (the exit code check still applies).Return Value
None. Raises Exception with the message "Script failed with exit code {exit_code}" if exec_result.exit_code is non-zero. Handles both streaming (iterator) and non-streaming (bytes) output transparently.