Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/modules/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 2 additions & 0 deletions openhands/core/config/sandbox_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default is 0.0.0.0 so this could be a breaking change. But agreed 127 is safer...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah.. you are right. It would be a breaking change but it is safer. As it is a breaking change do I have to change something to the PR or description to make it clear?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to validate that core functionality still works with this change (e.g. asking the agent to start an app), but need to get a docker image built...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mamoodi can you have a look at this one?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rbren I made the changes in #7017 and tested:

  • Accessing VS Code
  • Downloading workspace
  • Running a server shows up in App tab

They all are good on Mac.
Should I test this on Ubuntu and Windows as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! OK let's get this in

runtime_extra_build_args: list[str] | None = Field(default=None)
initialize_plugins: bool = Field(default=True)
force_rebuild_runtime: bool = Field(default=False)
Expand Down
19 changes: 16 additions & 3 deletions openhands/runtime/impl/docker/docker_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,29 @@ def _init_container(self):
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',
Expand Down
Loading