script

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Engine() (*sandbox.Engine, error)

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

func New(tools agentkit.ToolSet) *Runner

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

func (r *Runner) Run(ctx context.Context, source string) (string, error)

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.

func (*Runner) Tool

func (r *Runner) Tool() (agentkit.Tool, error)

Tool exposes the runner to the model as code_run. Pure compute needs no approval; actions the script performs are gated by the tools it calls through the gate.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL