sandbox_config.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. api_key: str | None = None
  33. base_container_image: str = 'nikolaik/python-nodejs:python3.11-nodejs22' # default to nikolaik/python-nodejs:python3.11-nodejs22 for eventstream runtime
  34. runtime_container_image: str | None = None
  35. user_id: int = os.getuid() if hasattr(os, 'getuid') else 1000
  36. timeout: int = 120
  37. enable_auto_lint: bool = (
  38. False # once enabled, OpenHands would lint files after editing
  39. )
  40. use_host_network: bool = False
  41. initialize_plugins: bool = True
  42. force_rebuild_runtime: bool = False
  43. runtime_extra_deps: str | None = None
  44. runtime_startup_env_vars: dict[str, str] = field(default_factory=dict)
  45. browsergym_eval_env: str | None = None
  46. def defaults_to_dict(self) -> dict:
  47. """Serialize fields to a dict for the frontend, including type hints, defaults, and whether it's optional."""
  48. dict = {}
  49. for f in fields(self):
  50. dict[f.name] = get_field_info(f)
  51. return dict
  52. def __str__(self):
  53. attr_str = []
  54. for f in fields(self):
  55. attr_name = f.name
  56. attr_value = getattr(self, f.name)
  57. attr_str.append(f'{attr_name}={repr(attr_value)}')
  58. return f"SandboxConfig({', '.join(attr_str)})"
  59. def __repr__(self):
  60. return self.__str__()