1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! Hyperlight micro-VM sandbox implementation.
//!
//! This module provides hardware-isolated sandbox execution using
//! Microsoft's Hyperlight technology. Hyperlight creates lightweight
//! micro-VMs with 1-2ms cold start time for secure code execution.
//!
//! ## Features
//!
//! - **Hardware Isolation**: Uses KVM (Linux) or Hyper-V (Windows)
//! - **Fast Cold Start**: 1-2ms to create new micro-VM
//! - **Pre-warmed Pool**: Optional pool of ready sandboxes
//! - **Configurable Limits**: Memory and timeout configuration
//!
//! ## Requirements
//!
//! - Linux with KVM or Windows with Hyper-V
//!
//! ## Usage
//!
//! ```rust,ignore
//! use acton_ai::tools::sandbox::{
//! HyperlightSandbox, HyperlightSandboxFactory, SandboxConfig
//! };
//!
//! // Create a factory
//! let factory = HyperlightSandboxFactory::new()?;
//!
//! // Create a sandbox
//! let sandbox = factory.create().await?;
//!
//! // Execute code
//! let result = sandbox.execute("echo hello", serde_json::json!({})).await?;
//! ```
//!
//! ## Pool Usage
//!
//! For lower latency, use the sandbox pool:
//!
//! ```rust,ignore
//! use acton_ai::tools::sandbox::{SandboxPool, SandboxConfig, WarmPool};
//!
//! // Create pool actor
//! let config = SandboxConfig::new().with_pool_size(Some(4));
//! let pool = SandboxPool::spawn(&mut runtime, config).await;
//!
//! // Warm up with pre-created sandboxes
//! pool.send(WarmPool { count: 4 }).await;
//!
//! // Acquire sandbox (returns pooled sandbox with auto-release)
//! let (tx, rx) = tokio::sync::oneshot::channel();
//! pool.send(AcquireSandbox { reply: tx }).await;
//! let sandbox = rx.await??;
//!
//! // Use sandbox...
//! ```
// Re-export all public types
pub use ;
pub use SandboxErrorKind;
pub use HyperlightSandboxFactory;
pub use ;
pub use ;
pub use SandboxProvider;
pub use HyperlightSandbox;
// AutoSandboxFactory is only available in tests (it silently falls back to stub)
pub use AutoSandboxFactory;