execution

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package execution runs one restricted, bounded Starlark program at a time.

Engine is compiled from the fixed language surface merged with process-neutral capability bindings. Each Execute call receives a request-specific NativeCall and converts only main's final value.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidProgram classifies invalid source, entrypoint behavior, or loading-phase native calls.
	ErrInvalidProgram = errors.New("invalid program")

	// ErrInvalidArguments classifies native arguments rejected before the native port.
	ErrInvalidArguments = errors.New("invalid capability arguments")

	// ErrPermissionDenied classifies a recognized authorization denial.
	ErrPermissionDenied = errors.New("permission denied")

	// ErrPolicyFailure classifies an authorization evaluation error or panic.
	ErrPolicyFailure = errors.New("authorization policy failure")

	// ErrResourceLimit classifies source, step, native-call, depth, or value-size exhaustion.
	ErrResourceLimit = errors.New("resource limit exceeded")

	// ErrCapabilityFailure classifies a native handler or handler-result failure.
	ErrCapabilityFailure = errors.New("capability failed")

	// ErrInternal classifies an unexpected runtime or contract failure.
	ErrInternal = errors.New("internal failure")
)

Functions

func SafeDetail

func SafeDetail(err error) (string, bool)

SafeDetail reports the model-derived suffix attached to err, if any.

Extraction follows the error chain with errors.As.

func WithSafeDetail

func WithSafeDetail(cause error, detail string) error

WithSafeDetail attaches detail to cause without changing cause.Error.

Empty detail returns cause unchanged. Callers must pass only model-derived suffixes; host-derived text must not be attached.

Types

type CapabilityBinding

type CapabilityBinding struct {
	// ID is the stable capability identity passed to NativeCall.
	ID string

	// Name is the dotted Starlark path used to assemble the frozen namespace.
	Name string

	// Input is the exact compiled input shape used to bind keyword arguments.
	Input []binding.FieldShape
}

CapabilityBinding is one process-neutral capability exposed to the interpreter.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine owns the frozen language surface and capability namespace shared by fresh execution threads.

func New

func New(bindings []CapabilityBinding) (*Engine, error)

New compiles one immutable execution engine from the fixed language surface and capability bindings.

func (*Engine) Execute

func (engine *Engine) Execute(
	source string,
	nativeCall NativeCall,
	limits Limits,
) (any, error)

Execute runs source in a fresh restricted interpreter and converts only main's final value.

type Limits

type Limits struct {
	// MaxSourceBytes bounds the submitted Starlark source length.
	MaxSourceBytes int

	// MaxExecutionSteps bounds abstract Starlark interpreter work.
	MaxExecutionSteps uint64

	// MaxNativeCalls bounds attempted capability invocations.
	MaxNativeCalls uint64

	// MaxValueDepth bounds recursive crossing-value conversion.
	MaxValueDepth int

	// MaxValueBytes supplies the byte-derived materialization bound.
	MaxValueBytes int
}

Limits contains the prevalidated positive budgets for one execution.

type NativeCall

type NativeCall func(id string, arguments map[string]any) (any, error)

NativeCall invokes one capability with a fresh canonical argument map.

It returns one normalized process-neutral value or a classified error.

Jump to

Keyboard shortcuts

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