scriptbox

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 13 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 scriptbox runs a trigger's transform script: a JavaScript function `(answer, memo) => ({items, memo})` written by an agent or the person, which only reshapes what the runtime fetched. It never fetches anything itself. Two walls stand around it:

  • the process: node under Landlock and seccomp (internal/confine, the helper of internal/designkit/kitadd): no sockets at all, nothing writable, only the system's and node's own folders readable, an empty environment, its heap capped (--max-old-space-size), killed after a few seconds whatever it does;
  • the script: a fresh vm context with no require, no process, no timers, no fetch, no code from strings, and a timeout on its run (200 ms by default).

The answer and the memo go in as JSON on stdin, the result comes back as JSON on stdout.

Index

Constants

View Source
const (
	DefaultTimeout  = 200 * time.Millisecond
	DefaultMemoryMB = 32

	// ScriptMax is the longest script taken.
	ScriptMax = 16 << 10
)

Limits of one run.

Variables

View Source
var ErrUnavailable = errors.New("scriptbox: scripts need node and Landlock on this machine")

ErrUnavailable: this machine cannot run a script safely (no node, or no Landlock).

Functions

func Available

func Available() bool

Available says whether a script can run here.

Types

type Options

type Options struct {
	Timeout  time.Duration
	MemoryMB int
	// Helper is the sandbox helper's command line up to its flags (this binary and kitadd.SandboxHelperArg).
	Helper []string
}

Options of a run; zero values take the defaults.

type Result

type Result struct {
	Items []any           `json:"items"`
	Memo  json.RawMessage `json:"memo,omitempty"`
}

Result is what the script gave back.

func Run

func Run(ctx context.Context, o Options, script string, answer any, memo json.RawMessage) (Result, error)

Run runs the script once on the answer and the memo.

Jump to

Keyboard shortcuts

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