#![deny(unsafe_code)]
#![warn(missing_docs)]
use parallax_core::{ExecutionLimits, Remediation};
use serde::{Deserialize, Serialize};
use std::time::Duration;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SandboxPolicy {
pub limits: ExecutionLimits,
pub allow_network: bool,
pub allow_fs_read: bool,
pub allow_fs_write: bool,
pub max_concurrent_workers: usize,
}
impl Default for SandboxPolicy {
fn default() -> Self {
Self {
limits: ExecutionLimits::default(),
allow_network: false,
allow_fs_read: true,
allow_fs_write: false,
max_concurrent_workers: 4,
}
}
}
impl SandboxPolicy {
pub fn strict() -> Self {
Self {
limits: ExecutionLimits {
timeout: Duration::from_secs(5),
max_output_bytes: 256 * 1024,
max_message_bytes: 4 * 1024 * 1024,
max_memory_bytes: Some(64 * 1024 * 1024),
max_fuel: Some(1_000_000),
},
allow_network: false,
allow_fs_read: false,
allow_fs_write: false,
max_concurrent_workers: 2,
}
}
pub fn validate(&self) -> Result<(), String> {
if self.limits.timeout.is_zero() {
return Err("timeout must be > 0".into());
}
if self.max_concurrent_workers == 0 {
return Err("max_concurrent_workers must be >= 1".into());
}
Ok(())
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct CapabilityToken {
pub name: String,
pub scope: Option<String>,
}
impl CapabilityToken {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
scope: None,
}
}
}
pub fn remediation_for_network() -> Remediation {
Remediation::with_detail(
"Disable network-dependent guest code or raise allow_network in policy",
"MVP adapters do not grant network access by default",
)
}