fix: make local runtime use host-writable paths and local cache defaults (#12015)

Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: Tim O'Farrell <tofarr@gmail.com>
This commit is contained in:
Wang Siyuan 2025-12-19 00:31:12 +08:00 committed by GitHub
parent aff9d69d41
commit d90579b398
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

View File

@ -1,8 +1,10 @@
import atexit
import json
import multiprocessing
import os
import time
import uuid
from pathlib import Path
import browsergym.core # noqa F401 (we register the openended task as a gym environment)
import gymnasium as gym
@ -67,6 +69,16 @@ class BrowserEnv:
raise BrowserInitException('Failed to start browser environment.')
def browser_process(self) -> None:
def _is_local_runtime() -> bool:
runtime_flag = os.getenv('RUNTIME', '').lower()
return runtime_flag == 'local'
# Default Playwright cache for local runs only; do not override in docker
if _is_local_runtime() and 'PLAYWRIGHT_BROWSERS_PATH' not in os.environ:
os.environ['PLAYWRIGHT_BROWSERS_PATH'] = str(
Path.home() / '.cache' / 'playwright'
)
if self.eval_mode:
assert self.browsergym_eval_env is not None
logger.info('Initializing browser env for web browsing evaluation.')
@ -87,6 +99,11 @@ class BrowserEnv:
)
env = gym.make(self.browsergym_eval_env, tags_to_mark='all', timeout=100000)
else:
downloads_path = os.getenv('BROWSERGYM_DOWNLOAD_DIR')
if not downloads_path and _is_local_runtime():
downloads_path = str(Path.home() / '.cache' / 'browsergym-downloads')
if not downloads_path:
downloads_path = '/workspace/.downloads/'
env = gym.make(
'browsergym/openended',
task_kwargs={'start_url': 'about:blank', 'goal': 'PLACEHOLDER_GOAL'},
@ -96,7 +113,7 @@ class BrowserEnv:
tags_to_mark='all',
timeout=100000,
pw_context_kwargs={'accept_downloads': True},
pw_chromium_kwargs={'downloads_path': '/workspace/.downloads/'},
pw_chromium_kwargs={'downloads_path': downloads_path},
)
obs, info = env.reset()

View File

@ -249,7 +249,22 @@ class LocalRuntime(ActionExecutionClient):
)
else:
# Set up workspace directory
# For local runtime, prefer a stable host path over /workspace defaults.
if (
self.config.workspace_base is None
and self.config.runtime
and self.config.runtime.lower() == 'local'
):
env_base = os.getenv('LOCAL_WORKSPACE_BASE')
if env_base:
self.config.workspace_base = os.path.abspath(env_base)
else:
self.config.workspace_base = os.path.abspath(
os.path.join(os.getcwd(), 'workspace', 'local')
)
if self.config.workspace_base is not None:
os.makedirs(self.config.workspace_base, exist_ok=True)
logger.warning(
f'Workspace base path is set to {self.config.workspace_base}. '
'It will be used as the path for the agent to run in. '