mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
* allow running app as root * better entrypoint mgmt * add nosetup option * remove comments * create docker group if it doesnt exist * better docker group mgmt * cast bools better * fix playwright * fix playwright for root * fix root source ~/.bashrc hangs by create clean bashrc --------- Co-authored-by: Xingyao Wang <xingyao6@illinois.edu>
59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
import os
|
|
from typing import Protocol
|
|
|
|
from opendevin.core.logger import opendevin_logger as logger
|
|
from opendevin.runtime.plugins.requirement import PluginRequirement
|
|
|
|
|
|
class SandboxProtocol(Protocol):
|
|
# https://stackoverflow.com/questions/51930339/how-do-i-correctly-add-type-hints-to-mixin-classes
|
|
|
|
def execute(self, cmd: str) -> tuple[int, str]: ...
|
|
|
|
def copy_to(self, host_src: str, sandbox_dest: str, recursive: bool = False): ...
|
|
|
|
|
|
class PluginMixin:
|
|
"""Mixin for Sandbox to support plugins."""
|
|
|
|
def init_plugins(self: SandboxProtocol, requirements: list[PluginRequirement]):
|
|
"""Load a plugin into the sandbox."""
|
|
|
|
# clean-up ~/.bashrc and touch ~/.bashrc
|
|
exit_code, output = self.execute('rm -f ~/.bashrc && touch ~/.bashrc')
|
|
if exit_code != 0:
|
|
raise RuntimeError(
|
|
f'Failed to clean-up ~/.bashrc with exit code {exit_code} and output {output}'
|
|
)
|
|
|
|
for requirement in requirements:
|
|
# copy over the files
|
|
self.copy_to(requirement.host_src, requirement.sandbox_dest, recursive=True)
|
|
logger.info(
|
|
f'Copied files from [{requirement.host_src}] to [{requirement.sandbox_dest}] inside sandbox.'
|
|
)
|
|
|
|
# Execute the bash script
|
|
abs_path_to_bash_script = os.path.join(
|
|
requirement.sandbox_dest, requirement.bash_script_path
|
|
)
|
|
logger.info(
|
|
f'Initializing plugin [{requirement.name}] by executing [{abs_path_to_bash_script}] in the sandbox.'
|
|
)
|
|
exit_code, output = self.execute(abs_path_to_bash_script)
|
|
if exit_code != 0:
|
|
raise RuntimeError(
|
|
f'Failed to initialize plugin {requirement.name} with exit code {exit_code} and output {output}'
|
|
)
|
|
logger.info(
|
|
f'Plugin {requirement.name} initialized successfully.'
|
|
)
|
|
|
|
if len(requirements) > 0:
|
|
exit_code, output = self.execute('source ~/.bashrc')
|
|
if exit_code != 0:
|
|
raise RuntimeError(
|
|
f'Failed to source ~/.bashrc with exit code {exit_code} and output {output}'
|
|
)
|
|
logger.info('Sourced ~/.bashrc successfully')
|