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 ¶
var ErrNoRuntime = errors.New("no container runtime")
ErrNoRuntime reports that no usable container runtime was found, so nothing was executed.
Functions ¶
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 ¶
Summary describes the isolation this profile enforces, for the report. Run prefixes it with the runtime name to form Result.Isolation.
func (Profile) WithDefaults ¶
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 ¶
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.