The OpenHands EventStream Runtime is the core component that enables secure and flexible execution of AI agent's action. It creates a sandboxed environment using Docker, where arbitrary code can be run safely without risking the host system.
OpenHands needs to execute arbitrary code in a secure, isolated environment for several reasons:
The OpenHands Runtime system uses a client-server architecture implemented with Docker containers. Here's an overview of how it works:
graph TD
A[User-provided Custom Docker Image] --> B[OpenHands Backend]
B -->|Builds| C[OH Runtime Image]
C -->|Launches| D[Action Executor]
D -->|Initializes| E[Browser]
D -->|Initializes| F[Bash Shell]
D -->|Initializes| G[Plugins]
G -->|Initializes| L[Jupyter Server]
B -->|Spawn| H[Agent]
B -->|Spawn| I[EventStream]
I <--->|Execute Action to
Get Observation
via REST API
| D
H -->|Generate Action| I
I -->|Obtain Observation| H
subgraph "Docker Container"
D
E
F
G
L
end
ActionExecutor inside the container, setting up necessary components like a bash shell and loading any specified pluginsopenhands/runtime/impl/eventstream/eventstream_runtime.py) communicates with the action execution server over RESTful API, sending actions and receiving observationsThe role of the client:
OpenHands' approach to building and managing runtime images ensures efficiency, consistency, and flexibility in creating and maintaining Docker images for both production and development environments.
Check out the relevant code if you are interested in more details.
OpenHands uses a dual-tagging system for its runtime images to balance reproducibility with flexibility. Tags may be in one of 2 formats:
oh_v{openhands_version}_{16_digit_lock_hash} (e.g.: oh_v0.9.9_1234567890abcdef)oh_v{openhands_version}_{16_digit_lock_hash}_{16_digit_source_hash}
(e.g.: oh_v0.9.9_1234567890abcdef_1234567890abcdef)This hash is built from the first 16 digits of the MD5 of:
nikolaik/python-nodejs:python3.12-nodejs22)pyproject.toml included in the image.poetry.lock included in the image.This effectively gives a hash for the dependencies of Openhands independent of the source code.
This is the first 16 digits of the MD5 of the directory hash for the source directory. This gives a hash for only the openhands source
When generating an image...
poetry install and
apt-get) except a final operation to copy the current source code. The new image is tagged with a
Specific tag only.This dual-tagging approach allows OpenHands to efficiently manage both development and production environments.
runtime:oh_v0.9.3_1234567890abcdef) always points to the latest build for a particular base image and OpenHands version combinationThe OpenHands Runtime supports a plugin system that allows for extending functionality and customizing the runtime environment. Plugins are initialized when the runtime client starts up.
Check an example of Jupyter plugin here if you want to implement your own plugin.
More details about the Plugin system are still under construction - contributions are welcomed!
Key aspects of the plugin system:
Plugin classALL_PLUGINS dictionaryAgent.sandbox_plugins: list[PluginRequirement]. Users can specify which plugins to load when initializing the runtime