mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 05:37:20 +08:00
Add core config to disable browser environment (#9570)
This commit is contained in:
@@ -212,6 +212,7 @@ def _load_runtime(
|
||||
runtime_startup_env_vars: dict[str, str] | None = None,
|
||||
docker_runtime_kwargs: dict[str, str] | None = None,
|
||||
override_mcp_config: MCPConfig | None = None,
|
||||
enable_browser: bool = True,
|
||||
) -> tuple[Runtime, OpenHandsConfig]:
|
||||
sid = 'rt_' + str(random.randint(100000, 999999))
|
||||
|
||||
@@ -221,6 +222,7 @@ def _load_runtime(
|
||||
|
||||
config = load_openhands_config()
|
||||
config.run_as_openhands = run_as_openhands
|
||||
config.enable_browser = enable_browser
|
||||
config.sandbox.force_rebuild_runtime = force_rebuild_runtime
|
||||
config.sandbox.keep_runtime_alive = False
|
||||
config.sandbox.docker_runtime_kwargs = docker_runtime_kwargs
|
||||
|
||||
@@ -15,6 +15,7 @@ from openhands.events.action import (
|
||||
from openhands.events.observation import (
|
||||
BrowserOutputObservation,
|
||||
CmdOutputObservation,
|
||||
ErrorObservation,
|
||||
FileDownloadObservation,
|
||||
)
|
||||
|
||||
@@ -122,6 +123,26 @@ def find_element_by_tag_and_attributes(
|
||||
return None
|
||||
|
||||
|
||||
def test_browser_disabled(temp_dir, runtime_cls, run_as_openhands):
|
||||
runtime, _ = _load_runtime(
|
||||
temp_dir, runtime_cls, run_as_openhands, enable_browser=False
|
||||
)
|
||||
|
||||
action_cmd = CmdRunAction(command='python3 -m http.server 8000 > server.log 2>&1 &')
|
||||
logger.info(action_cmd, extra={'msg_type': 'ACTION'})
|
||||
obs = runtime.run_action(action_cmd)
|
||||
logger.info(obs, extra={'msg_type': 'OBSERVATION'})
|
||||
|
||||
action_browse = BrowseURLAction(url='http://localhost:8000', return_axtree=False)
|
||||
logger.info(action_browse, extra={'msg_type': 'ACTION'})
|
||||
obs = runtime.run_action(action_browse)
|
||||
logger.info(obs, extra={'msg_type': 'OBSERVATION'})
|
||||
assert isinstance(obs, ErrorObservation)
|
||||
assert 'Browser functionality is not supported or disabled' in obs.content
|
||||
|
||||
_close_test_runtime(runtime)
|
||||
|
||||
|
||||
def test_simple_browse(temp_dir, runtime_cls, run_as_openhands):
|
||||
runtime, config = _load_runtime(temp_dir, runtime_cls, run_as_openhands)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user