Add CORS origins support to Docker sandbox service for remote browser access#12489
Merged
Add CORS origins support to Docker sandbox service for remote browser access#12489
Conversation
… access
This change adds CORS (Cross-Origin Resource Sharing) support to the Docker
sandbox service, matching the existing implementation in the remote sandbox
service. This fixes an issue where users running OpenHands via Docker on a
remote server (e.g., Ubuntu Server VM) would encounter WebSocket connection
failures when accessing the UI from an external machine.
Changes:
- Added ALLOW_CORS_ORIGINS_VARIABLE constant ('OH_ALLOW_CORS_ORIGINS_0')
- Added web_url field to DockerSandboxService dataclass
- Updated start_sandbox() to set CORS origins when web_url is configured
- Updated DockerSandboxServiceInjector to retrieve web_url from global config
- Added unit tests for CORS functionality
When users configure WEB_HOST or web_url, the Docker sandbox service will now
pass the OH_ALLOW_CORS_ORIGINS_0 environment variable to agent-server containers,
allowing them to accept requests from remote browsers.
This complements the existing SANDBOX_CONTAINER_URL_PATTERN environment variable
for remote access scenarios.
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
This was referenced Jan 21, 2026
Closed
1 task
4 tasks
8 tasks
Contributor
|
Hi @tofarr, is your self-hosted OpenHands currently working? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of PR
This PR adds CORS (Cross-Origin Resource Sharing) support to the Docker sandbox service, matching the existing implementation in the remote sandbox service. This fixes an issue where users running OpenHands via Docker on a remote server (e.g., Ubuntu Server VM) would encounter WebSocket connection failures when accessing the UI from an external machine.
Changes:
ALLOW_CORS_ORIGINS_VARIABLEconstant (OH_ALLOW_CORS_ORIGINS_0) to docker_sandbox_service.pyweb_urlfield toDockerSandboxServicedataclassstart_sandbox()to set CORS origins environment variable whenweb_urlis configuredDockerSandboxServiceInjectorto retrieveweb_urlfrom global config and pass it to the serviceWhen users configure
WEB_HOSTorweb_url, the Docker sandbox service will now pass theOH_ALLOW_CORS_ORIGINS_0environment variable to agent-server containers, allowing them to accept requests from remote browsers.This complements the existing
SANDBOX_CONTAINER_URL_PATTERNenvironment variable for remote access scenarios.Demo Screenshots/Videos
N/A - Backend infrastructure change
Change Type
Checklist
Fixes
Resolves the issue discussed in Discord where users running OpenHands on a remote server couldn't access from external browsers due to CORS errors with WebSocket connections.
Release Notes
Added CORS support to Docker sandbox service for remote browser access. Users running OpenHands on remote servers should set
WEB_HOSTenvironment variable (e.g.,WEB_HOST=192.168.1.100:3000) along withSANDBOX_CONTAINER_URL_PATTERNfor proper remote access configuration.@tofarr can click here to continue refining the PR
To run this PR locally, use the following command:
GUI with Docker: