use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use crate::error::SandboxError;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SandboxArtifact {
pub path: String,
pub content: String,
}
#[derive(Debug, Clone)]
pub struct ExecutionResult {
pub exit_code: i32,
pub stdout: String,
pub stderr: String,
pub execution_time_ms: u64,
pub artifacts: Vec<SandboxArtifact>,
}
impl ExecutionResult {
#[must_use]
pub const fn is_success(&self) -> bool {
self.exit_code == 0
}
}
#[async_trait]
pub trait Sandbox: Send + Sync {
async fn execute(&self, code: &str) -> Result<ExecutionResult, SandboxError>;
async fn is_ready(&self) -> Result<bool, SandboxError>;
async fn stop(&self) -> Result<(), SandboxError>;
}
#[async_trait]
impl Sandbox for Box<dyn Sandbox> {
async fn execute(&self, code: &str) -> Result<ExecutionResult, SandboxError> {
(**self).execute(code).await
}
async fn is_ready(&self) -> Result<bool, SandboxError> {
(**self).is_ready().await
}
async fn stop(&self) -> Result<(), SandboxError> {
(**self).stop().await
}
}