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"
: Executes the prebuilt image on the HUD platform. Good for sharing or running complex setups.
image_or_build_context
(str |Path
):- If string, it is interpreted as an image name. Both local and remote locations support this. One caveat is that local images are not supported when
location="remote"
, since the HUD platform does not have access to your local Docker daemon. - If
Path
, it is interpreted as a directory containing a Dockerfile and other files needed to build the image. This is useful for local development. See Local Environment Structure below.
- If string, it is interpreted as an image name. Both local and remote locations support this. One caveat is that local images are not supported when
Local Environment Structure
When creating a custom environment, the directory specified by image_or_build_context
must contain:
Dockerfile
: Defines the base image, system dependencies, Python dependencies (often viapip install -e .
), and installs your controller package.pyproject.toml
: Defines your controller as an installable Python package. The package must be namedhud_controller
.src/
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.
Using a Custom Environment
Use your CustomGym
object with hud.gym.make()
:
Hot Reloading
The HUD SDK supports hot reloading of controller code. When using a build context, if the controller code in the folder is updated, the SDK will automatically reinstall the controller package without needing to rebuild the image. This is done by:
- Copying the controller code to a temporary directory.
pip install -e . --break-system-packages
to install the controller package.
Note that docker images cannot be hot reloaded, and will only be rebuilt when a new environment is created.
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.