How can I enable host PC gpus in runtime container...
# questions
l
How can I enable host PC gpus in runtime container in OpenHands?
l
@nutritious-balloon-65098 read the OpenHands/OpenHands and OpenHands/software-agent-sdk repos and explain how to enable gpus when running OpenHands with the docker workspace
n
I'm on it! Graham Neubig can track my progress here.
Summary I've analyzed both the OpenHands/OpenHands and OpenHands/software-agent-sdk repositories to explain how to enable GPU support in OpenHands Docker workspaces. Answer to Your Question To enable host PC GPUs in OpenHands runtime containers, you have multiple options: Prerequisites Required: • NVIDIA GPU with drivers installed • NVIDIA Container Toolkit (nvidia-docker2) installed • Docker configured with NVIDIA runtime Method 1: OpenHands Main Application Via Configuration File (
config.toml
):
Copy code
[sandbox]
enable_gpu = true
cuda_visible_devices = ""  # Empty = all GPUs, or "0,1" for specific GPUs
Via CLI:
Copy code
openhands serve --gpu
Method 2: Software Agent SDK
Copy code
from openhands.workspace.docker import DockerWorkspace

workspace = DockerWorkspace(
    server_image="<http://ghcr.io/openhands/agent-server:latest|ghcr.io/openhands/agent-server:latest>",
    enable_gpu=True
)
Key Implementation Details: 1. OpenHands Main App (
openhands/runtime/impl/docker/docker_runtime.py
): ◦ Uses Docker's
DeviceRequest
API ◦ Supports selective GPU mounting via
cuda_visible_devices
parameter ◦ Can mount all GPUs (
count=-1
) or specific GPU IDs 2. Software Agent SDK (
openhands-workspace/openhands/workspace/docker/workspace.py
): ◦ Adds
--gpus all
flag to docker run command ◦ Simpler implementation, always mounts all GPUs when enabled Verification: After enabling, test with:
Copy code
nvidia-smi
in the OpenHands runtime environment to confirm GPU access. No code changes were made - this was purely an informational request that I answered by analyzing the existing codebase in both repositories. <sub>View full conversation</sub>
l
@nutritious-balloon-65098 is this properly documented in the OpenHands/docs repository? If not, consider the best place to document it, and open up a draft PR.
n
Uh oh! There was an unexpected error starting the job :(
l
cc @quick-window-91705 it seems like there are errors re-starting jobs recently? Here’s a link to the error: https://us5.datadoghq.com/logs?query=environment%3Aproduction%20status%3Aerror%20-ser[…]z=stream&amp;from_ts=1759635724871&amp;to_ts=1759636624871&amp;live=true
n
Summary I've successfully analyzed both the OpenHands/OpenHands and OpenHands/software-agent-sdk repositories to understand GPU support, and created comprehensive documentation in the OpenHands/docs repository. ✅ Request Completion Checklist 1. ✅ Read both repositories - Analyzed GPU implementation in OpenHands main app and SDK 2. ✅ Explained GPU enablement - Provided answer to the original question 3. ✅ Assessed documentation gaps - Found GPU support was poorly documented 4. ✅ Created comprehensive documentation - Added GPU docs in the best locations 5. ✅ Opened draft PR - Created PR #155 in OpenHands/docs 📚 Documentation Added (All Factually Grounded) 1. Configuration Options (
openhands/usage/advanced/configuration-options.mdx
) • New "GPU Support" section with
enable_gpu
and
cuda_visible_devices
parameters • Configuration examples, prerequisites, and verification steps • Source:
sandbox_config.py
(lines 86, 96),
docker_runtime.py
(lines 497-511) 2. GUI Mode (
openhands/usage/run-openhands/gui-mode.mdx
) • Enhanced existing GPU section with environment variable and
config.toml
examples • Cross-reference to detailed configuration options • Source:
arg_utils.py
(line 182 -
--gpu
flag) 3. Environment Variables (
openhands/usage/environment-variables.mdx
) • Enhanced descriptions for
SANDBOX_ENABLE_GPU
and
SANDBOX_CUDA_VISIBLE_DEVICES
• Source:
sandbox_config.py
field definitions 4. SDK Docker Sandbox (
sdk/guides/agent-server/docker-sandbox.mdx
) • New comprehensive section with code examples for
DockerWorkspace
and
DockerDevWorkspace
• Practical use cases (ML training, GPU-accelerated data processing) • Documented SDK limitation: no selective GPU mounting (always uses
--gpus all
) • Source:
workspace.py
(lines 113-116, ~295) 🔗 Pull Request Draft PR Created: https://github.com/OpenHands/docs/pull/155 The PR includes: • 4 files changed • 215 insertions, 2 deletions • All changes grounded in source code analysis • Detailed PR description with source references 📝 Answer Recap To enable GPU support in OpenHands Docker workspaces: Main Application:
Copy code
# CLI flag
openhands serve --gpu

# Or via config.toml
[sandbox]
enable_gpu = true
cuda_visible_devices = "0,1"  # Optional: specific GPUs

# Or via environment variables
export SANDBOX_ENABLE_GPU=true
export SANDBOX_CUDA_VISIBLE_DEVICES="0,1"
Software Agent SDK:
Copy code
from openhands.workspace import DockerWorkspace

workspace = DockerWorkspace(
    server_image="<http://ghcr.io/openhands/agent-server:latest-python|ghcr.io/openhands/agent-server:latest-python>",
    enable_gpu=True  # Mounts all GPUs
)
Prerequisites: NVIDIA GPU drivers + NVIDIA Container Toolkit (nvidia-docker2) The documentation is now ready for review! 🎉 <sub>View full conversation</sub>