sandbox

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sandbox provides bubblewrap-based sandboxed command execution.

It wraps bwrap to run bash commands in an isolated filesystem with network access but no host filesystem access beyond explicit mounts. ExecConfig carries per-execution env vars and mounts, and is threaded through context via ContextWithExecConfig / ExecConfigFromContext so tools can access it without explicit parameter threading.

Plane: shared

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithExecConfig

func ContextWithExecConfig(ctx context.Context, cfg *ExecConfig) context.Context

ContextWithExecConfig stores an ExecConfig in the context.

func Seconds

func Seconds(s int) time.Duration

Seconds returns a duration from a seconds count.

Types

type ExecConfig

type ExecConfig struct {
	Env       []string // Extra env vars passed to the sandboxed process
	MountDirs []Mount  // Additional read-only bind mounts
}

ExecConfig holds per-execution sandbox settings.

func ExecConfigFromContext

func ExecConfigFromContext(ctx context.Context) *ExecConfig

ExecConfigFromContext retrieves the ExecConfig from the context. Returns nil if not set.

type Mount

type Mount struct {
	Source   string
	Target   string
	ReadOnly bool
}

Mount represents a filesystem mount inside the sandbox.

type Sandbox

type Sandbox struct {
	BwrapPath        string
	Timeout          time.Duration
	AllowUnsandboxed bool // if false (default), fail hard when bwrap is unavailable
}

Sandbox wraps bubblewrap for isolated command execution.

func (*Sandbox) Exec

func (s *Sandbox) Exec(
	ctx context.Context, command string, cfg *ExecConfig,
) (stdout, stderr string, exitCode int, err error)

Exec runs a bash command inside the bubblewrap sandbox. If bwrap is unavailable and AllowUnsandboxed is false, it returns an error. If AllowUnsandboxed is true (dev mode), it falls back to direct exec.

func (*Sandbox) IsAvailable

func (s *Sandbox) IsAvailable() bool

IsAvailable checks whether bwrap is available at the configured path.

Jump to

Keyboard shortcuts

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