pub struct LuaSandbox { /* private fields */ }Expand description
A sandboxed Lua 5.4 VM.
Implementations§
Source§impl LuaSandbox
impl LuaSandbox
Sourcepub fn new() -> SoulResult<Self>
pub fn new() -> SoulResult<Self>
Create a new sandboxed Lua VM.
Removes dangerous globals: io, os, debug, require, loadfile,
dofile, load.
Sourcepub fn lua(&self) -> &Lua
pub fn lua(&self) -> &Lua
Get a reference to the inner Lua VM (for registering custom functions).
Sourcepub fn set_string(&self, name: &str, value: &str) -> SoulResult<()>
pub fn set_string(&self, name: &str, value: &str) -> SoulResult<()>
Set a string global variable.
Sourcepub fn set_json(&self, name: &str, value: &Value) -> SoulResult<()>
pub fn set_json(&self, name: &str, value: &Value) -> SoulResult<()>
Set a JSON value as a Lua global (recursively converts objects/arrays to tables).
Sourcepub fn exec(&self, code: &str) -> SoulResult<String>
pub fn exec(&self, code: &str) -> SoulResult<String>
Execute Lua code and return the result as a string.
Sourcepub async fn exec_with_timeout(
&self,
code: &str,
timeout_secs: u64,
) -> SoulResult<String>
pub async fn exec_with_timeout( &self, code: &str, timeout_secs: u64, ) -> SoulResult<String>
Execute Lua code with a timeout (wall-clock seconds).
Sourcepub fn take_output(&self) -> Vec<String>
pub fn take_output(&self) -> Vec<String>
Take accumulated output buffer contents.
Sourcepub fn take_final_answer(&self) -> Option<String>
pub fn take_final_answer(&self) -> Option<String>
Check if final_answer has been called, and take the value.
Sourcepub fn has_final_answer(&self) -> bool
pub fn has_final_answer(&self) -> bool
Check if final_answer has been set (without consuming it).
Sourcepub fn get_global_string(&self, name: &str) -> SoulResult<Option<String>>
pub fn get_global_string(&self, name: &str) -> SoulResult<Option<String>>
Read a Lua global variable and return it as a string.
Used by final_var(varname) to return a REPL variable as the answer
without requiring the LLM to serialize it into final_answer().
Sourcepub fn register_llm_query(&self, channel: LlmQueryChannel) -> SoulResult<()>
pub fn register_llm_query(&self, channel: LlmQueryChannel) -> SoulResult<()>
Register llm_query(prompt) and llm_query_batched(prompts) functions.
These let Lua code make synchronous sub-LLM calls. The functions block on a channel — the RLM engine fulfills requests asynchronously on the other end.
Auto Trait Implementations§
impl Freeze for LuaSandbox
impl !RefUnwindSafe for LuaSandbox
impl Send for LuaSandbox
impl Sync for LuaSandbox
impl Unpin for LuaSandbox
impl UnsafeUnpin for LuaSandbox
impl !UnwindSafe for LuaSandbox
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more