pub mod e2b;
pub mod native;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
pub use e2b::E2BSandbox;
pub use native::{NativeConfig, NativeRunner};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum SandboxTier {
None,
Docker,
GVisor,
Firecracker,
E2B,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExecutionResult {
pub exit_code: i32,
pub stdout: String,
pub stderr: String,
pub execution_time_ms: u64,
pub success: bool,
}
impl ExecutionResult {
pub fn success(stdout: String, execution_time_ms: u64) -> Self {
Self {
exit_code: 0,
stdout,
stderr: String::new(),
execution_time_ms,
success: true,
}
}
pub fn failure(exit_code: i32, stderr: String, execution_time_ms: u64) -> Self {
Self {
exit_code,
stdout: String::new(),
stderr,
execution_time_ms,
success: false,
}
}
pub fn error(error_message: String) -> Self {
Self {
exit_code: -1,
stdout: String::new(),
stderr: error_message,
execution_time_ms: 0,
success: false,
}
}
}
#[async_trait]
pub trait SandboxRunner: Send + Sync {
async fn execute(
&self,
code: &str,
env: HashMap<String, String>,
) -> Result<ExecutionResult, anyhow::Error>;
}