"""Base classes and data types for the Code Sandbox extension.""" from abc import ABC, abstractmethod from dataclasses import dataclass from pathlib import Path from typing import Optional @dataclass class ExecutionResult: """Result of sandbox code or command execution.""" stdout: str stderr: str exit_code: int duration_seconds: float timed_out: bool = False @property def success(self) -> bool: return self.exit_code == 0 and not self.timed_out class BaseSandboxBackend(ABC): """Abstract interface for a sandbox execution backend.""" @abstractmethod def is_available(self) -> bool: """Check if this backend can be used on the current host system.""" pass @abstractmethod async def execute( self, cmd: list[str], workspace_dir: Path, timeout: int, allow_network: bool = False, env: Optional[dict[str, str]] = None, ) -> ExecutionResult: """Execute a command inside the isolated sandbox.""" pass