mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Engel Nyst <engel.nyst@gmail.com>
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from typing import AsyncGenerator
|
|
|
|
from fastapi import Request
|
|
from pydantic import Field
|
|
|
|
from openhands.app_server.sandbox.preset_sandbox_spec_service import (
|
|
PresetSandboxSpecService,
|
|
)
|
|
from openhands.app_server.sandbox.sandbox_spec_models import (
|
|
SandboxSpecInfo,
|
|
)
|
|
from openhands.app_server.sandbox.sandbox_spec_service import (
|
|
SandboxSpecService,
|
|
SandboxSpecServiceInjector,
|
|
get_agent_server_env,
|
|
get_agent_server_image,
|
|
)
|
|
from openhands.app_server.services.injector import InjectorState
|
|
|
|
|
|
def get_default_sandbox_specs():
|
|
return [
|
|
SandboxSpecInfo(
|
|
id=get_agent_server_image(),
|
|
command=['python', '-m', 'openhands.agent_server'],
|
|
initial_env={
|
|
# VSCode disabled for now
|
|
'OH_ENABLE_VS_CODE': '0',
|
|
**get_agent_server_env(),
|
|
},
|
|
working_dir='',
|
|
)
|
|
]
|
|
|
|
|
|
class ProcessSandboxSpecServiceInjector(SandboxSpecServiceInjector):
|
|
specs: list[SandboxSpecInfo] = Field(
|
|
default_factory=get_default_sandbox_specs,
|
|
description='Preset list of sandbox specs',
|
|
)
|
|
|
|
async def inject(
|
|
self, state: InjectorState, request: Request | None = None
|
|
) -> AsyncGenerator[SandboxSpecService, None]:
|
|
yield PresetSandboxSpecService(specs=self.specs)
|