sandbox_config.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 default sandbox action execution.
  14. remote_runtime_init_timeout: The timeout for the remote runtime to start.
  15. enable_auto_lint: Whether to enable auto-lint.
  16. use_host_network: Whether to use the host network.
  17. initialize_plugins: Whether to initialize plugins.
  18. force_rebuild_runtime: Whether to force rebuild the runtime image.
  19. runtime_extra_deps: The extra dependencies to install in the runtime image (typically used for evaluation).
  20. This will be rendered into the end of the Dockerfile that builds the runtime image.
  21. It can contain any valid shell commands (e.g., pip install numpy).
  22. The path to the interpreter is available as $OH_INTERPRETER_PATH,
  23. which can be used to install dependencies for the OH-specific Python interpreter.
  24. runtime_startup_env_vars: The environment variables to set at the launch of the runtime.
  25. This is a dictionary of key-value pairs.
  26. This is useful for setting environment variables that are needed by the runtime.
  27. For example, for specifying the base url of website for browsergym evaluation.
  28. browsergym_eval_env: The BrowserGym environment to use for evaluation.
  29. Default is None for general purpose browsing. Check evaluation/miniwob and evaluation/webarena for examples.
  30. platform: The platform on which the image should be built. Default is None.
  31. """
  32. remote_runtime_api_url: str = 'http://localhost:8000'
  33. local_runtime_url: str = 'http://localhost'
  34. keep_runtime_alive: bool = True
  35. api_key: str | None = None
  36. base_container_image: str = 'nikolaik/python-nodejs:python3.12-nodejs22' # default to nikolaik/python-nodejs:python3.12-nodejs22 for eventstream runtime
  37. runtime_container_image: str | None = None
  38. user_id: int = os.getuid() if hasattr(os, 'getuid') else 1000
  39. timeout: int = 120
  40. remote_runtime_init_timeout: int = 180
  41. enable_auto_lint: bool = (
  42. False # once enabled, OpenHands would lint files after editing
  43. )
  44. use_host_network: bool = False
  45. initialize_plugins: bool = True
  46. force_rebuild_runtime: bool = False
  47. runtime_extra_deps: str | None = None
  48. runtime_startup_env_vars: dict[str, str] = field(default_factory=dict)
  49. browsergym_eval_env: str | None = None
  50. platform: str | None = None
  51. def defaults_to_dict(self) -> dict:
  52. """Serialize fields to a dict for the frontend, including type hints, defaults, and whether it's optional."""
  53. dict = {}
  54. for f in fields(self):
  55. dict[f.name] = get_field_info(f)
  56. return dict
  57. def __str__(self):
  58. attr_str = []
  59. for f in fields(self):
  60. attr_name = f.name
  61. attr_value = getattr(self, f.name)
  62. attr_str.append(f'{attr_name}={repr(attr_value)}')
  63. return f"SandboxConfig({', '.join(attr_str)})"
  64. def __repr__(self):
  65. return self.__str__()