Documentation
¶
Overview ¶
Package script runs untrusted JavaScript on the sandbox interpreter (QuickJS compiled to wasm) and bridges a script's actions through a single generic host gate onto the SAME agentkit tools the model uses.
The interpreter guest declares exactly ONE host import — nocturn.call — and the host side of it is a dispatcher over an agentkit.ToolSet: the guest calls nocturn.call(tool, args), the dispatcher looks the tool up and runs its Call. That toolset is the same gated set the model dispatches through, so a script reaches an action through the identical authorization path (the gate + out-of-band HITL). One gate is the reference monitor; adding a tool is a Go-side change and never rebuilds the interpreter.
Pure compute needs no approval: a script that never calls the gate performs no action. Each action it does perform is gated individually by the tool it names.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Engine ¶
Engine returns the process-wide QuickJS interpreter engine (compiled once, shared). A plugin whose artifact is JavaScript runs on this same engine — one interpreter for every code_run and JS plugin.
func Prelude ¶
func Prelude() string
Prelude returns the JS prelude to prepend to a guest program (both the code_run script and every JS plugin). The outward-facing APIs it defines bottom out at nocturn.call, so the gate + HITL still judge every action — the prelude is DevEx sugar, not a security boundary.
Types ¶
type Runner ¶
type Runner struct {
Timeout time.Duration // per-run wall-clock bound (0 = sandbox default)
// contains filtered or unexported fields
}
Runner evaluates JS source on the QuickJS interpreter, dispatching a script's nocturn.call actions through a shared agentkit.ToolSet — the SAME set the model dispatches through, so script actions are gated and observed identically. Build it with New; the zero value is not usable.
func New ¶
New builds a Runner over the shared QuickJS interpreter engine and the given tools — the same set the model dispatches through, so script actions are gated and observed identically. This is the only constructor: a Runner always drives the interpreter (and always prepends the runtime prelude). A nil toolset yields an empty one (every call reports "unknown tool"). The engine is compiled lazily on the first Run, not here.
func (*Runner) Run ¶
Run evaluates source on the interpreter and returns what the script printed to stdout. The runtime prelude (fetch/fs/btoa/…) is always prepended — a Runner only ever drives the JS interpreter. A trap, non-zero exit, memory exhaustion, or timeout returns an error alongside any stderr the guest produced. Output is not truncated here — the caller bounds what the model sees; a script's own action results stay whole.