Custom Environments
Define and run your own Docker-based environments locally or remotely
Custom Environments
While the HUD SDK provides standard environments like "hud-browser"
and "OSWorld-Ubuntu"
, you can also define and run your own custom environments using Docker. This allows you to create specific testing scenarios with custom software stacks or configurations.
Custom environments are defined using the CustomGym
type from hud.types
.
Defining a Custom Environment (CustomGym
)
Key CustomGym
Attributes:
location
("local"
|"remote"
):"local"
: Builds and runs the Docker container on your local machine. Requires Docker installed. Ideal for development. See Local Environment Structure below."remote"
: Sends thedockerfile
content to the HUD platform for remote build and execution. Good for sharing or running complex setups.
dockerfile
(str | None): The Dockerfile content.- Required if
location="remote"
. - Optional if
location="local"
andcontroller_source_dir
is provided (will look forDockerfile
inside that directory).
- Required if
controller_source_dir
(str |Path
| None):- Only relevant for
location="local"
. - Path to your local directory containing the controller code and potentially the
Dockerfile
. This directory is mounted into the container.
- Only relevant for
Local Environment Structure
When creating a local
custom environment, the directory specified by controller_source_dir
typically contains:
Dockerfile
: Defines the base image, system dependencies, Python dependencies (often viapip install -e .
), and the command to run your controller script (CMD [...]
).pyproject.toml
: Defines your controller as an installable Python package. The HUD SDK reads the[project.name]
from this file to know how to import your controller code within the container after installation.src/
(or your package name): A directory containing your Python controller code. This code needs to implement the functions called bysetup
,evaluate
, andstep
(e.g., interacting with applications inside the container, returning observations).
Example Structure (./my_custom_controller/
):
- Examples: The top-level
environments/
directory in the SDK repository contains reference implementations (likenovnc_ubuntu
) following this structure. - Dependencies: For local custom environments, you might need to install development dependencies using
pip install -e ".[dev]"
in your SDK checkout to ensure the local components (like the Docker client) function correctly.
Using a Custom Environment
Use your CustomGym
object with hud.gym.make()
:
Creating a custom environment requires careful design of both the Dockerfile and the controller script to ensure they work together correctly.
Related Concepts
- Environment: The runtime instance created from the
CustomGym
spec. - Task: Can specify a
CustomGym
object in itsgym
attribute to request your custom environment. - Advanced Environment Control: Using
invoke
andexecute
for debugging or advanced control.