2026-01-14 07:19:34 +08:00
|
|
|
from src.sandbox.local.local_sandbox import LocalSandbox
|
|
|
|
|
from src.sandbox.sandbox_provider import SandboxProvider
|
|
|
|
|
|
|
|
|
|
_singleton: LocalSandbox | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LocalSandboxProvider(SandboxProvider):
|
2026-01-16 14:44:51 +08:00
|
|
|
def __init__(self):
|
|
|
|
|
"""Initialize the local sandbox provider with path mappings."""
|
|
|
|
|
self._path_mappings = self._setup_path_mappings()
|
|
|
|
|
|
|
|
|
|
def _setup_path_mappings(self) -> dict[str, str]:
|
|
|
|
|
"""
|
|
|
|
|
Setup path mappings for local sandbox.
|
|
|
|
|
|
|
|
|
|
Maps container paths to actual local paths, including skills directory.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
Dictionary of path mappings
|
|
|
|
|
"""
|
|
|
|
|
mappings = {}
|
|
|
|
|
|
|
|
|
|
# Map skills container path to local skills directory
|
|
|
|
|
try:
|
|
|
|
|
from src.config import get_app_config
|
|
|
|
|
|
|
|
|
|
config = get_app_config()
|
|
|
|
|
skills_path = config.skills.get_skills_path()
|
|
|
|
|
container_path = config.skills.container_path
|
|
|
|
|
|
|
|
|
|
# Only add mapping if skills directory exists
|
|
|
|
|
if skills_path.exists():
|
|
|
|
|
mappings[container_path] = str(skills_path)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
# Log but don't fail if config loading fails
|
|
|
|
|
print(f"Warning: Could not setup skills path mapping: {e}")
|
|
|
|
|
|
|
|
|
|
return mappings
|
|
|
|
|
|
2026-01-15 13:22:30 +08:00
|
|
|
def acquire(self, thread_id: str | None = None) -> str:
|
2026-01-14 07:19:34 +08:00
|
|
|
global _singleton
|
|
|
|
|
if _singleton is None:
|
2026-01-16 14:44:51 +08:00
|
|
|
_singleton = LocalSandbox("local", path_mappings=self._path_mappings)
|
2026-01-14 07:19:34 +08:00
|
|
|
return _singleton.id
|
|
|
|
|
|
|
|
|
|
def get(self, sandbox_id: str) -> None:
|
2026-01-14 12:32:34 +08:00
|
|
|
if sandbox_id == "local":
|
|
|
|
|
if _singleton is None:
|
|
|
|
|
self.acquire()
|
|
|
|
|
return _singleton
|
|
|
|
|
return None
|
2026-01-14 07:19:34 +08:00
|
|
|
|
|
|
|
|
def release(self, sandbox_id: str) -> None:
|
|
|
|
|
pass
|