Skip to main content

LuaSandbox

Struct LuaSandbox 

Source
pub struct LuaSandbox { /* private fields */ }
Expand description

A sandboxed Lua 5.4 VM.

Implementations§

Source§

impl LuaSandbox

Source

pub fn new() -> SoulResult<Self>

Create a new sandboxed Lua VM.

Removes dangerous globals: io, os, debug, require, loadfile, dofile, load.

Source

pub fn lua(&self) -> &Lua

Get a reference to the inner Lua VM (for registering custom functions).

Source

pub fn set_string(&self, name: &str, value: &str) -> SoulResult<()>

Set a string global variable.

Source

pub fn set_json(&self, name: &str, value: &Value) -> SoulResult<()>

Set a JSON value as a Lua global (recursively converts objects/arrays to tables).

Source

pub fn exec(&self, code: &str) -> SoulResult<String>

Execute Lua code and return the result as a string.

Source

pub async fn exec_with_timeout( &self, code: &str, timeout_secs: u64, ) -> SoulResult<String>

Execute Lua code with a timeout (wall-clock seconds).

Source

pub fn take_output(&self) -> Vec<String>

Take accumulated output buffer contents.

Source

pub fn take_final_answer(&self) -> Option<String>

Check if final_answer has been called, and take the value.

Source

pub fn has_final_answer(&self) -> bool

Check if final_answer has been set (without consuming it).

Source

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().

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> MaybeSend for T
where T: Send,