mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
feat: Add configurable sandbox host_port and container_url_pattern for remote access (#12255)
Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Tim O'Farrell <tofarr@gmail.com>
This commit is contained in:
@@ -67,7 +67,8 @@ def get_default_persistence_dir() -> Path:
|
||||
def get_default_web_url() -> str | None:
|
||||
"""Get legacy web host parameter.
|
||||
|
||||
If present, we assume we are running under https."""
|
||||
If present, we assume we are running under https.
|
||||
"""
|
||||
web_host = os.getenv('WEB_HOST')
|
||||
if not web_host:
|
||||
return None
|
||||
@@ -175,7 +176,17 @@ def config_from_env() -> AppServerConfig:
|
||||
elif os.getenv('RUNTIME') in ('local', 'process'):
|
||||
config.sandbox = ProcessSandboxServiceInjector()
|
||||
else:
|
||||
config.sandbox = DockerSandboxServiceInjector()
|
||||
# Support legacy environment variables for Docker sandbox configuration
|
||||
docker_sandbox_kwargs: dict = {}
|
||||
if os.getenv('SANDBOX_HOST_PORT'):
|
||||
docker_sandbox_kwargs['host_port'] = int(
|
||||
os.environ['SANDBOX_HOST_PORT']
|
||||
)
|
||||
if os.getenv('SANDBOX_CONTAINER_URL_PATTERN'):
|
||||
docker_sandbox_kwargs['container_url_pattern'] = os.environ[
|
||||
'SANDBOX_CONTAINER_URL_PATTERN'
|
||||
]
|
||||
config.sandbox = DockerSandboxServiceInjector(**docker_sandbox_kwargs)
|
||||
|
||||
if config.sandbox_spec is None:
|
||||
if os.getenv('RUNTIME') == 'remote':
|
||||
|
||||
@@ -426,8 +426,23 @@ class DockerSandboxService(SandboxService):
|
||||
class DockerSandboxServiceInjector(SandboxServiceInjector):
|
||||
"""Dependency injector for docker sandbox services."""
|
||||
|
||||
container_url_pattern: str = 'http://localhost:{port}'
|
||||
host_port: int = 3000
|
||||
container_url_pattern: str = Field(
|
||||
default='http://localhost:{port}',
|
||||
description=(
|
||||
'URL pattern for exposed sandbox ports. Use {port} as placeholder. '
|
||||
'For remote access, set to your server IP (e.g., http://192.168.1.100:{port}). '
|
||||
'Configure via OH_SANDBOX_CONTAINER_URL_PATTERN environment variable.'
|
||||
),
|
||||
)
|
||||
host_port: int = Field(
|
||||
default=3000,
|
||||
description=(
|
||||
'The port on which the main OpenHands app server is running. '
|
||||
'Used for webhook callbacks from agent-server containers. '
|
||||
'If running OpenHands on a non-default port, set this to match. '
|
||||
'Configure via OH_SANDBOX_HOST_PORT environment variable.'
|
||||
),
|
||||
)
|
||||
container_name_prefix: str = 'oh-agent-server-'
|
||||
max_num_sandboxes: int = Field(
|
||||
default=5,
|
||||
|
||||
Reference in New Issue
Block a user