sandbox_config.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import os
  2. from dataclasses import dataclass, field, fields
  3. from openhands.core.config.config_utils import get_field_info
  4. @dataclass
  5. class SandboxConfig:
  6. """Configuration for the sandbox.
  7. Attributes:
  8. remote_runtime_api_url: The hostname for the Remote Runtime API.
  9. local_runtime_url: The default hostname for the local runtime. You may want to change to http://host.docker.internal for DIND environments
  10. base_container_image: The base container image from which to build the runtime image.
  11. runtime_container_image: The runtime container image to use.
  12. user_id: The user ID for the sandbox.
  13. timeout: The timeout for the sandbox.
  14. enable_auto_lint: Whether to enable auto-lint.
  15. use_host_network: Whether to use the host network.
  16. initialize_plugins: Whether to initialize plugins.
  17. force_rebuild_runtime: Whether to force rebuild the runtime image.
  18. runtime_extra_deps: The extra dependencies to install in the runtime image (typically used for evaluation).
  19. This will be rendered into the end of the Dockerfile that builds the runtime image.
  20. It can contain any valid shell commands (e.g., pip install numpy).
  21. The path to the interpreter is available as $OH_INTERPRETER_PATH,
  22. which can be used to install dependencies for the OH-specific Python interpreter.
  23. runtime_startup_env_vars: The environment variables to set at the launch of the runtime.
  24. This is a dictionary of key-value pairs.
  25. This is useful for setting environment variables that are needed by the runtime.
  26. For example, for specifying the base url of website for browsergym evaluation.
  27. browsergym_eval_env: The BrowserGym environment to use for evaluation.
  28. Default is None for general purpose browsing. Check evaluation/miniwob and evaluation/webarena for examples.
  29. """
  30. remote_runtime_api_url: str = 'http://localhost:8000'
  31. local_runtime_url: str = 'http://localhost'
  32. keep_remote_runtime_alive: bool = True
  33. api_key: str | None = None
  34. base_container_image: str = 'nikolaik/python-nodejs:python3.12-nodejs22' # default to nikolaik/python-nodejs:python3.12-nodejs22 for eventstream runtime
  35. runtime_container_image: str | None = None
  36. user_id: int = os.getuid() if hasattr(os, 'getuid') else 1000
  37. timeout: int = 120
  38. enable_auto_lint: bool = (
  39. False # once enabled, OpenHands would lint files after editing
  40. )
  41. use_host_network: bool = False
  42. initialize_plugins: bool = True
  43. force_rebuild_runtime: bool = False
  44. runtime_extra_deps: str | None = None
  45. runtime_startup_env_vars: dict[str, str] = field(default_factory=dict)
  46. browsergym_eval_env: str | None = None
  47. def defaults_to_dict(self) -> dict:
  48. """Serialize fields to a dict for the frontend, including type hints, defaults, and whether it's optional."""
  49. dict = {}
  50. for f in fields(self):
  51. dict[f.name] = get_field_info(f)
  52. return dict
  53. def __str__(self):
  54. attr_str = []
  55. for f in fields(self):
  56. attr_name = f.name
  57. attr_value = getattr(self, f.name)
  58. attr_str.append(f'{attr_name}={repr(attr_value)}')
  59. return f"SandboxConfig({', '.join(attr_str)})"
  60. def __repr__(self):
  61. return self.__str__()