sandbox

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DenyInit added in v0.9.3

func DenyInit(args []string)

DenyInit is called early in main when the binary is re-exec'd as a sandbox deny-path wrapper. It runs as root (UID 0) inside the user namespace so it can mount tmpfs over denied paths. After mounting, it spawns the agent in a nested user namespace (via exec.Command + CLONE_NEWUSER) mapped to the real UID, so the agent doesn't see root.

We can't use syscall.Unshare(CLONE_NEWUSER) because Go processes are multi-threaded; unshare requires single-threaded. Instead we use exec.Command which clones before the child has threads.

Args format: --uid UID --gid GID --deny PATH [--deny PATH...] -- CMD ARGS...

Types

type Config

type Config struct {
	Isolation     Level
	Mounts        []Mount
	Deny          []string // paths to mask (e.g. ~/.ssh)
	AllowOutbound bool     // allow outbound network even if isolation denies it
	Timeout       time.Duration
	CPULimit      time.Duration // RLIMIT_CPU (0 = backend default)
	MemLimit      uint64        // RLIMIT_AS in bytes (0 = backend default)
	MaxFDs        uint32        // RLIMIT_NOFILE (0 = backend default)
}

Config holds sandbox creation parameters.

type EnforcementError added in v0.8.4

type EnforcementError struct {
	Gaps     []string
	Platform string
}

EnforcementError is returned when the system cannot enforce the requested sandbox config.

func (*EnforcementError) Error added in v0.8.4

func (e *EnforcementError) Error() string

type Level

type Level int

Level defines the isolation level for a sandbox.

const (
	Strict     Level = iota // No network, minimal fs, short TTL
	Standard                // No network, mounted dirs only
	Network                 // Network allowed, mounted dirs only
	Privileged              // Full access (for trusted skills)
)

func ParseLevel

func ParseLevel(s string) Level

ParseLevel converts a string to a Level.

func (Level) String

func (l Level) String() string

type Mount

type Mount struct {
	Source   string
	Target   string
	ReadOnly bool
}

Mount describes a filesystem mount for the sandbox.

type Sandbox

type Sandbox interface {
	Exec(ctx context.Context, name string, args []string) (*exec.Cmd, error)
	PostStart(pid int) error // apply rlimits etc. after process starts
	Destroy() error
}

Sandbox provides isolated execution of commands.

func New

func New(cfg Config) (Sandbox, error)

New creates a platform-appropriate sandbox. Returns EnforcementError if the platform cannot enforce the requested isolation — no silent fallback.

Jump to

Keyboard shortcuts

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