sandbox

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 17 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 sandbox runs untrusted code (model-written proofs of concept and candidate fixes) inside a locked-down container by driving the docker or podman CLI.

Nothing in this package executes target or model-written code on the host. When no container runtime is available Detect returns ErrNoRuntime and the caller marks proofs as not run.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRuntime = errors.New("no container runtime")

ErrNoRuntime reports that no usable container runtime was found, so nothing was executed.

Functions

func BuildArgs

func BuildArgs(spec Spec, stageDir, name string) ([]string, error)

BuildArgs returns the full runtime argument vector for a spec, without executing anything. stageDir is the host directory holding Files (mounted read-only at /spackle-in); name is the container name. It is exported so the isolation defaults are unit-testable without a runtime.

Types

type Profile

type Profile struct {
	// Network is "none" (default) or "scope". "scope" attaches the default bridge network so a
	// proof can reach an authorized running target; it is never chosen by this package.
	Network  string
	MemoryMB int           // default 1024
	CPUs     float64       // default 2
	PIDs     int           // default 256
	Timeout  time.Duration // default 2m; hard cap 15m
}

Profile is the isolation applied to one run.

func (Profile) Summary

func (p Profile) Summary() string

Summary describes the isolation this profile enforces, for the report. Run prefixes it with the runtime name to form Result.Isolation.

func (Profile) WithDefaults

func (p Profile) WithDefaults() Profile

WithDefaults returns the profile with every zero field replaced by its default.

type Result

type Result struct {
	ExitCode  int
	Stdout    string // capped at 1 MiB, with a truncation note
	Stderr    string // capped at 1 MiB
	TimedOut  bool
	Duration  time.Duration
	Isolation string   // human-readable summary of what was enforced, for the report
	Argv      []string // the runtime command line that was executed
}

Result is the outcome of one execution.

type Runtime

type Runtime interface {
	Name() string // "docker" or "podman"
	Run(ctx context.Context, spec Spec) (Result, error)
	ImagePresent(ctx context.Context, image string) bool
	Pull(ctx context.Context, image string) error
}

Runtime is a container engine that can run a Spec.

func Detect

func Detect(ctx context.Context, preferred string) (Runtime, error)

Detect finds a working runtime. preferred is "auto", "docker", "podman" or "none". It returns ErrNoRuntime (wrapped with a what/why/what-to-do message) when preferred is "none", when no CLI is on PATH, or when the CLI is present but the engine does not answer (`<cli> version --format {{.Server.Version}}` with a 15s timeout).

type Spec

type Spec struct {
	Image string
	// Cmd is the program and arguments run inside the container, in the work directory.
	Cmd []string
	// SourceDir is a host directory mounted read-only and copied into the writable work
	// directory before Cmd runs. Empty means start with an empty work directory.
	SourceDir string
	// Files are extra files written into the work directory after the source copy (the PoC or
	// a patched file). Keys are forward-slash relative paths; they are validated.
	Files map[string]string
	// Subdir is a relative directory inside the work directory to run Cmd in.
	Subdir  string
	Env     map[string]string
	Profile Profile
}

Spec is one execution.

Jump to

Keyboard shortcuts

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