Dsxir. Predictor. CodeExec. Sandbox
(dsxir v0.4.0)
Copy Markdown
Wraps Dune.eval_string/2. The only module in dsxir that references Dune.
Inputs are injected as a bindings prelude: each {name, value} becomes a
bound variable name = <inspected value> prepended to the generated code,
so generated code references the signature's input fields by name. The value
of the last expression is the result.
Bindings round-trip limitation
Binding values are serialised via inspect/1 and re-parsed inside the Dune
sandbox. This only works for terms whose inspect/1 output is valid Elixir
source: strings, numbers, atoms, booleans, lists, and plain maps. Structs
whose Inspect implementation emits a #-sigil representation (e.g.
#Dsxir.Primitives.History<...>) are not supported as bindings, nor are
PIDs, references, or anonymous functions.
Recognised opts
The following keys are forwarded to Dune; all other keys are ignored:
exec_timeout, max_heap_size, max_reductions, atom_pool_size, and
allowlist.
Summary
Functions
Evaluates code in the Dune sandbox with bindings prepended as a prelude.
Functions
@spec eval(String.t(), keyword(), keyword()) :: {:ok, %{value: term(), inspected: String.t(), stdio: String.t()}} | {:error, %{type: atom(), message: String.t(), stdio: String.t()}}
Evaluates code in the Dune sandbox with bindings prepended as a prelude.
Returns {:ok, %{value, inspected, stdio}} on success, or
{:error, %{type, message, stdio}} where type is the Dune failure type
(:restricted, :timeout, :exception, :parsing, :memory,
:reductions, etc.).