{"record":{"id":"aa6a1634f4488cc1","repo":"BoundaryML/baml","slug":"baml-panics-hostunavailable","errorCode":"baml.panics.HostUnavailable","errorMessage":"host resource '{resource}' unavailable: {message}","messagePattern":"host resource '(.+?)' unavailable: (.+?)","errorType":"error_code","errorClass":"VmPanic","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm_types/src/errors.rs","lineNumber":85,"sourceCode":"    ///\n    /// Catchable in user code as `baml.panics.Exit` — patterned after\n    /// Python's `SystemExit`: code can intercept it for cleanup or\n    /// testing, and if nothing catches it the engine surfaces the code\n    /// as `EngineError::Exit` and the host terminates with it.\n    ///\n    /// BAML `int` is `i64`, so the signal carries the full value the\n    /// user wrote; the host narrows to `i32` for `std::process::exit`.\n    #[error(\"baml.sys.exit({code})\")]\n    Exit { code: i64 },\n\n    /// The graceful-ish way to handle potential OOM errors, instead of hard-crashing.\n    #[error(\"memory allocation failed: {message}\")]\n    AllocFailure { message: String },\n\n    /// A required host resource is unavailable — e.g. the OS entropy source\n    /// returned an error in a sandboxed runtime. Catchable so user code can\n    /// fall back gracefully instead of aborting the host process.\n    #[error(\"host resource '{resource}' unavailable: {message}\")]\n    HostUnavailable { resource: String, message: String },\n\n    /// The right operand of a bigint shift (`<<` / `>>`) was negative.\n    /// Catchable because the count is a runtime `bigint` and the type\n    /// system can't rule out negative values.\n    #[error(\"negative bit shift: {message}\")]\n    NegativeBitShift { message: String },\n\n    /// A host callable returned a value of the wrong type, or threw a value\n    /// that does not match its declared `throws` contract `E`. Surfaces in\n    /// BAML as `baml.panics.HostContractViolation`.\n    ///\n    /// `class_name` / `language` are populated when the violation arose from\n    /// a host throw (echoing the offending host exception's identity) and\n    /// `None` when it arose from a wrong-type return (no exception class to\n    /// echo).\n    #[error(\"host contract violation: {message} [class={class_name:?}, lang={language:?}]\")]\n    HostContractViolation {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm_types/src/errors.rs#L67-L103","documentation":"This panic variant indicates a required host resource is unavailable, typically because the OS entropy source returned an error in a sandboxed runtime. It is deliberately catchable so BAML user code can fall back gracefully rather than aborting the host process.","triggerScenarios":"BAML code requests a host-provided resource (e.g. random entropy via the host interface) and the host reports it unavailable — for example getrandom/OS entropy failing inside a sandbox, WASM runtime without entropy wired up, or a blocked system call.","commonSituations":"Running BAML in WASM/sandboxed environments where the entropy source (e.g. /dev/urandom, getrandom syscall) is not available or is denied by the sandbox policy; misconfigured runtimes missing host imports.","solutions":["Check the sandbox/runtime configuration and ensure the entropy source (getrandom) is available or a custom RNG is wired into the host.","Catch baml.panics.HostUnavailable and switch to a deterministic or alternate resource path in BAML code.","Fix environment issues: mount/clear access to the OS entropy device or update the sandbox policy to allow the resource.","Upgrade the host runtime so required host imports are implemented."],"exampleFix":"// before\nlet id = rand.uuid(); // panics if entropy unavailable in sandbox\n// after\ntry {\n  id = rand.uuid();\n} catch e: baml.panics.HostUnavailable {\n  id = deterministic_fallback_id();\n}","handlingStrategy":"fallback","validationCode":"// Check host resource availability at startup where possible\nlet ok = host.has_resource(\"entropy\");","typeGuard":null,"tryCatchPattern":"try {\n  let v = rand.uuid();\n} catch e: baml.panics.HostUnavailable {\n  let v = fallback_id_source();\n}","preventionTips":["Ensure the sandbox/WASM runtime wires up entropy (getrandom) before running programs.","Test BAML programs inside the target sandbox, not only natively.","Provide deterministic fallbacks for random-dependent logic in restricted environments.","Keep host runtime imports implemented and up to date."],"tags":["host-resource","entropy","sandbox","runtime","catchable"],"backgroundTag":"host-resource-unavailable","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}