use serde::{ Serialize, Deserialize };
use core::time::Duration;
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub struct CodeExecutionConfig
{
pub runtime : CodeRuntime,
pub timeout : Duration,
pub memory_limit : usize,
pub allowed_imports : Vec< String >,
pub security_level : SecurityLevel,
}
impl Default for CodeExecutionConfig
{
#[ inline ]
fn default() -> Self
{
Self
{
runtime : CodeRuntime::Python,
timeout : Duration::from_secs( 30 ),
memory_limit : 128 * 1024 * 1024, allowed_imports : vec![
"os".to_string(),
"sys".to_string(),
"json".to_string(),
"math".to_string(),
"datetime".to_string(),
],
security_level : SecurityLevel::Sandbox,
}
}
}
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub enum CodeRuntime
{
Python,
JavaScript,
Rust,
Go,
Custom
{
name : String,
image : String,
},
}
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub enum SecurityLevel
{
Sandbox,
Restricted,
Trusted,
}
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub struct CodeExecutionResult
{
pub output : String,
pub error : Option< String >,
pub execution_time : Duration,
pub memory_used : usize,
pub return_code : i32,
}