@@ -78,6 +78,8 @@ pub enum HyperlightError {
7878    ExecutionAccessViolation ( u64 ) , 
7979
8080    /// Guest execution was cancelled by the host 
81+ /// 
82+ /// **This error poisons the sandbox.** See [`crate::MultiUseSandbox::clear_poison()`] for recovery options. 
8183#[ error( "Execution was cancelled by the host." ) ]  
8284    ExecutionCanceledByHost ( ) , 
8385
@@ -90,6 +92,8 @@ pub enum HyperlightError {
9092    FieldIsMissingInGuestLogData ( String ) , 
9193
9294    /// Guest aborted during outb 
95+ /// 
96+ /// **This error poisons the sandbox.** See [`crate::MultiUseSandbox::clear_poison()`] for recovery options. 
9397#[ error( "Guest aborted: {0} {1}" ) ]  
9498    GuestAborted ( u8 ,  String ) , 
9599
@@ -191,6 +195,36 @@ pub enum HyperlightError {
191195#[ error( "Failure processing PE File {0:?}" ) ]  
192196    PEFileProcessingFailure ( #[ from]   goblin:: error:: Error ) , 
193197
198+     /// The sandbox is poisoned due to an inconsistent internal state that could lead to 
199+ /// undefined behavior, memory corruption, or security vulnerabilities. 
200+ /// 
201+ /// ## What causes poisoning? 
202+ /// 
203+ /// Sandbox poisoning occurs when operations leave the sandbox in an inconsistent state: 
204+ /// 
205+ /// ### Guest Function Panics/Aborts 
206+ /// - **Heap Memory Leaks**: When a guest function panics or aborts, the call stack is not 
207+ ///   properly unwound, leaving heap allocations permanently leaked 
208+ /// - **Resource Leaks**: File handles, network connections, or other resources may remain 
209+ ///   open and unreachable 
210+ /// - **Partial State Updates**: Data structures may be left in an inconsistent state 
211+ ///   (e.g., half-updated linked lists, corrupted hash tables) 
212+ /// 
213+ /// ### Interrupted Function Calls 
214+ /// When you interrupt an in-progress guest function with [`InterruptHandle::kill()`]: 
215+ /// - **Memory Allocations**: Heap memory allocated during the call remains leaked 
216+ /// - **Mutex/Lock State**: Guest-side mutexes may remain locked, causing deadlocks 
217+ /// - **I/O Buffers**: Partially written buffers may contain corrupted data 
218+ /// - **Global State**: Static variables may be left in an inconsistent state 
219+ /// 
220+ /// ## Recovery 
221+ /// 
222+ /// - **Safe**: Restore from a non-poisoned snapshot using [`MultiUseSandbox::restore()`] 
223+ /// - **Unsafe**: Clear poison manually with [`MultiUseSandbox::clear_poison()`] (only if you 
224+ ///   understand the inconsistent state and have manually resolved it) 
225+ #[ error( "The sandbox was poisoned" ) ]  
226+     PoisonedSandbox , 
227+ 
194228    /// Raw pointer is less than base address 
195229#[ error( "Raw pointer ({0:?}) was less than the base address ({1})" ) ]  
196230    RawPointerLessThanBaseAddress ( RawPtr ,  u64 ) , 
0 commit comments