sandbox

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: MIT Purpose: OS-level isolation for shell command execution. On Linux it uses Landlock (kernel >= 5.13) to restrict filesystem and network access. On other platforms it falls back to a no-op with an explicit warning so callers can surface degraded isolation to the user.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyAndExec

func ApplyAndExec() error

ApplyAndExec is called from main() when os.Args[1] == "__sandbox_exec". It applies the sandbox to the current process then execs the target. On platforms without Landlock support (kernel < 5.13) it degrades gracefully: the command still runs but with a warning.

Types

type Policy

type Policy struct {
	// ReadOnlyPaths are directories the command may read but not modify.
	ReadOnlyPaths []string
	// ReadWritePaths are directories the command may read and modify.
	// Typically the project workdir and a scratch temp dir — nothing else.
	ReadWritePaths []string
	// AllowNetwork controls outbound network access. Default false.
	AllowNetwork bool
	// Timeout is the hard wall-clock limit for the command.
	Timeout time.Duration
}

Policy describes what a sandboxed command may access.

func DefaultPolicy

func DefaultPolicy(workdir, tmpDir string) Policy

DefaultPolicy returns the recommended policy for agent bash execution: read/write only inside workdir and tmpDir, read-only system paths, no network.

type Result

type Result struct {
	// Enforced is true when OS-level sandboxing was active.
	Enforced bool
	// Mechanism names the isolation backend ("landlock", "none").
	Mechanism string
	// Warning is non-empty when isolation is degraded.
	Warning string
}

Result reports how the command was isolated.

func Command

func Command(ctx context.Context, policy Policy, name string, args ...string) (*exec.Cmd, Result, error)

Command builds an *exec.Cmd whose process is confined by the given policy where the platform supports it. The returned Result tells the caller whether enforcement is active so it can warn the user.

Jump to

Keyboard shortcuts

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