Jido. Tools. LuaEval
(Jido Action v2.3.0)
View Source
Execute a Lua code string in a sandboxed VM and return the values.
Features
- Safe by default: Uses tv-labs/lua's sandbox defaults to disable unsafe functions
- Timeout protection: Configurable timeout with task isolation
- Global injection: Pass Elixir values into the Lua environment
- Flexible returns: Return all values or just the first one
Security
By default, the following unsafe Lua libraries are disabled:
os(getenv, execute, exit, etc.)ioandfilepackage,require,dofileload,loadfile,loadstring
Safe libraries remain enabled:
string,math,table- Basic Lua operations
Set enable_unsafe_libs: true to disable sandboxing (use with caution).
Examples
# Simple arithmetic
iex> Jido.Tools.LuaEval.run(%{code: "return 2 + 2"}, %{})
{:ok, %{results: [4]}}
# With globals
iex> Jido.Tools.LuaEval.run(%{
code: "return x + 5",
globals: %{"x" => 10}
}, %{})
{:ok, %{results: [15]}}
# Return first value only
iex> Jido.Tools.LuaEval.run(%{
code: "return 1, 2, 3",
return_mode: :first
}, %{})
{:ok, %{result: 1}}
# Timeout protection
iex> Jido.Tools.LuaEval.run(%{
code: "while true do end",
timeout_ms: 50
}, %{})
{:error, %Jido.Action.Error.TimeoutError{timeout: 50}}
Summary
Functions
Returns the Action metadata. Alias for to_json/0.
Returns the category of the Action.
Returns the description of the Action.
Returns the name of the Action.
Lifecycle hook called after Action execution.
Lifecycle hook called after output validation.
Lifecycle hook called after parameter validation.
Lifecycle hook called before output validation.
Lifecycle hook called before parameter validation.
Lifecycle hook called when an error occurs.
Returns the output schema of the Action.
Executes the Action with the given parameters and context.
Returns the input schema of the Action.
Returns the tags associated with the Action.
Returns the Action metadata as a JSON-serializable map.
Converts the Action to an LLM-compatible tool format.
Validates the output result for the Action.
Validates the input parameters for the Action.
Returns the version of the Action.
Functions
Returns the Action metadata. Alias for to_json/0.
Returns the category of the Action.
Returns the description of the Action.
Returns the name of the Action.
Lifecycle hook called after Action execution.
Lifecycle hook called after output validation.
Lifecycle hook called after parameter validation.
Lifecycle hook called before output validation.
Lifecycle hook called before parameter validation.
Lifecycle hook called when an error occurs.
Returns the output schema of the Action.
Executes the Action with the given parameters and context.
The run/2 function must be implemented in the module using Jido.Action.
Returns the input schema of the Action.
Returns the tags associated with the Action.
Returns the Action metadata as a JSON-serializable map.
Converts the Action to an LLM-compatible tool format.
Validates the output result for the Action.
Examples
iex> defmodule ExampleAction do
...> use Jido.Action,
...> name: "example_action",
...> output_schema: [
...> result: [type: :string, required: true]
...> ]
...> end
...> ExampleAction.validate_output(%{result: "test", extra: "ignored"})
{:ok, %{result: "test", extra: "ignored"}}
iex> ExampleAction.validate_output(%{extra: "ignored"})
{:error, "Invalid output for Action: Required key :result not found"}
Validates the input parameters for the Action.
Examples
iex> defmodule ExampleAction do
...> use Jido.Action,
...> name: "example_action",
...> schema: [
...> input: [type: :string, required: true]
...> ]
...> end
...> ExampleAction.validate_params(%{input: "test"})
{:ok, %{input: "test"}}
iex> ExampleAction.validate_params(%{})
{:error, "Invalid parameters for Action: Required key :input not found"}
Returns the version of the Action.