sandbox_config.py 2.9 KB

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