Skip to content

🙌 OpenHands: AI-Driven Development

feat: Adding sandbox property runtime_binding_address to specify whic… (#6992)

Fredy Sierra2b3c38d06103
diff --git a/docs/modules/usage/configuration-options.md b/docs/modules/usage/configuration-options.md
index f1f2f44ef5..22811197e5 100644
--- a/docs/modules/usage/configuration-options.md
+++ b/docs/modules/usage/configuration-options.md
@@ -385,6 +385,11 @@ To use these with the docker command, pass in `-e SANDBOX_<option>`. Example: `-
- Default: `false`
- Description: Use host network
+- `runtime_binding_address`
+ - Type: `str`
+ - Default: `127.0.0.1`
+ - Description: The binding address for the runtime ports. It specifies which network interface on the host machine Docker should bind the runtime ports to.
+
### Linting and Plugins
- `enable_auto_lint`
- Type: `bool`
diff --git a/openhands/core/config/sandbox_config.py b/openhands/core/config/sandbox_config.py
index 47fbc9295c..e4e43af0a6 100644
--- a/openhands/core/config/sandbox_config.py
+++ b/openhands/core/config/sandbox_config.py
@@ -17,6 +17,7 @@ class SandboxConfig(BaseModel):
remote_runtime_api_timeout: The timeout for the remote runtime API requests.
enable_auto_lint: Whether to enable auto-lint.
use_host_network: Whether to use the host network.
+ runtime_binding_address: The binding address for the runtime ports. It specifies which network interface on the host machine Docker should bind the runtime ports to.
initialize_plugins: Whether to initialize plugins.
force_rebuild_runtime: Whether to force rebuild the runtime image.
runtime_extra_deps: The extra dependencies to install in the runtime image (typically used for evaluation).
@@ -60,6 +61,7 @@ class SandboxConfig(BaseModel):
default=False
) # once enabled, OpenHands would lint files after editing
use_host_network: bool = Field(default=False)
+ runtime_binding_address: str = Field(default='127.0.0.1')
runtime_extra_build_args: list[str] | None = Field(default=None)
initialize_plugins: bool = Field(default=True)
force_rebuild_runtime: bool = Field(default=False)
diff --git a/openhands/runtime/impl/docker/docker_runtime.py b/openhands/runtime/impl/docker/docker_runtime.py
index ecb1386a68..e4c698f9dd 100644
--- a/openhands/runtime/impl/docker/docker_runtime.py
+++ b/openhands/runtime/impl/docker/docker_runtime.py
@@ -201,16 +201,29 @@ class DockerRuntime(ActionExecutionClient):
port_mapping: dict[str, list[dict[str, str]]] | None = None
if not use_host_network:
port_mapping = {
- f'{self._container_port}/tcp': [{'HostPort': str(self._host_port)}],
+ f'{self._container_port}/tcp': [
+ {
+ 'HostPort': str(self._host_port),
+ 'HostIp': self.config.sandbox.runtime_binding_address,
+ }
+ ],
}
if self.vscode_enabled:
port_mapping[f'{self._vscode_port}/tcp'] = [
- {'HostPort': str(self._vscode_port)}
+ {
+ 'HostPort': str(self._vscode_port),
+ 'HostIp': self.config.sandbox.runtime_binding_address,
+ }
]
for port in self._app_ports:
- port_mapping[f'{port}/tcp'] = [{'HostPort': str(port)}]
+ port_mapping[f'{port}/tcp'] = [
+ {
+ 'HostPort': str(port),
+ 'HostIp': self.config.sandbox.runtime_binding_address,
+ }
+ ]
else:
self.log(
'warn',