sandbox

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 16 Imported by: 4 modules, 3 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

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotImplemented = errors.New("not implemented")
	ErrAgentRequired  = errors.New("requires agent installed on the sandbox")
)

Functions

This section is empty.

Types

type Arg

type Arg struct {
	Type   ArgsType
	Params interface{}
}

type ArgsType

type ArgsType uint8
const (
	Bool ArgsType = iota
	Folders
	Capabilities
	Namespaces
	SystemCalls
)

type BindMount added in v0.1.1

type BindMount struct {
	HostPath    string
	SandboxPath string
}

BindMount represents a bind mount configuration

type BubblewrapCommandOptions added in v0.1.1

type BubblewrapCommandOptions struct {
	// The command to execute
	Command string

	// Arguments for the command
	Args []string

	// Per-command bind mounts (e.g., source file location -> sandbox location)
	CommandBinds []BindMount

	// Working directory for this command
	WorkingDir string

	// Change to this directory before running
	Chdir string

	// Per-command environment variables (merged with static ones)
	Environment map[string]string

	// Input for stdin
	Stdin string
}

BubblewrapCommandOptions holds per-command configuration

type BubblewrapConfiguration added in v0.1.1

type BubblewrapConfiguration struct {
	// Base directory for temporary sandbox files
	TempDir string

	// Static namespace options (applied to all commands)
	UnsharePID     bool // Create a new PID namespace
	UnshareIPC     bool // Create a new IPC namespace
	UnshareNetwork bool // Create a new network namespace
	UnshareUTS     bool // Create a new UTS namespace
	UnshareUser    bool // Create a new user namespace
	UnshareCgroup  bool // Create a new cgroup namespace

	// Static security options (applied to all commands)
	NewSession bool // Create a new session (prevents TIOCSTI attacks)
	UID        int  // UID to run as inside the sandbox
	GID        int  // GID to run as inside the sandbox

	// Seccomp filter file
	SeccompFile string

	// Static bind mounts (read-only system directories)
	ReadOnlySystemBinds []BindMount

	// Static environment variables
	Environment map[string]string

	// Enable host filesystem access (read-only)
	HostFilesystem bool
}

BubblewrapConfiguration holds the general configuration for bubblewrap sandboxing

type BubblewrapSandbox added in v0.1.1

type BubblewrapSandbox struct {
	// contains filtered or unexported fields
}

BubblewrapSandbox implements sandboxing using bubblewrap (bwrap)

func NewBubblewrapSandbox added in v0.1.1

func NewBubblewrapSandbox(ctx context.Context, config *BubblewrapConfiguration) (*BubblewrapSandbox, error)

NewBubblewrapSandbox creates a new bubblewrap sandbox

func (*BubblewrapSandbox) Clear added in v0.1.1

func (b *BubblewrapSandbox) Clear() error

Clear cleans up the temp directory

func (*BubblewrapSandbox) ExecuteWithOptions added in v0.1.1

func (b *BubblewrapSandbox) ExecuteWithOptions(ctx context.Context, options *BubblewrapCommandOptions) (*types.Result, error)

ExecuteWithOptions executes a command with specific per-command options

func (*BubblewrapSandbox) Run added in v0.1.1

func (b *BubblewrapSandbox) Run(ctx context.Context, cmd string) (*types.Result, error)

Run executes a command in the bubblewrap sandbox with default options

func (*BubblewrapSandbox) RunScript added in v0.1.1

func (b *BubblewrapSandbox) RunScript(ctx context.Context, source string) (*types.Result, error)

RunScript runs a script in the bubblewrap sandbox

func (*BubblewrapSandbox) RunSource added in v0.1.1

func (b *BubblewrapSandbox) RunSource(ctx context.Context, source string) (*types.Result, error)

RunSource executes source code in the bubblewrap sandbox It creates a specific source directory, places the script file inside, and mounts only that directory

func (*BubblewrapSandbox) Start added in v0.1.1

func (b *BubblewrapSandbox) Start() error

Start starts the sandbox (no-op for bubblewrap as it runs per-command)

func (*BubblewrapSandbox) Stop added in v0.1.1

func (b *BubblewrapSandbox) Stop() error

Stop stops the sandbox (no-op for bubblewrap as each command runs independently)

func (*BubblewrapSandbox) Wait added in v0.1.1

func (b *BubblewrapSandbox) Wait() error

Wait waits for the sandbox to finish (no-op for bubblewrap)

type Configuration

type Configuration struct {
	Rules []Rule
}

type DockerConfiguration added in v0.1.1

type DockerConfiguration struct {
	Image           string            // Docker image to use (e.g., "ubuntu:20.04", "alpine:latest")
	WorkingDir      string            // Working directory inside container
	Environment     map[string]string // Environment variables
	NetworkMode     string            // Network mode (bridge, host, etc.)
	NetworkDisabled bool              // Disable networking entirely
	User            string            // User to run as inside container
	Memory          string            // Memory limit (e.g., "512m", "1g")
	CPULimit        string            // CPU limit (e.g., "0.5", "1.0")
	Timeout         time.Duration     // Command timeout
	Remove          bool              // Whether to remove container after execution
}

DockerConfiguration represents the configuration for Docker sandbox

type DockerSourceOptions added in v0.1.1

type DockerSourceOptions struct {
	// Interpreter runs the source file. If it is empty or the source starts
	// with a shebang, the source file runs directly.
	Interpreter string
	// InterpreterArgs are passed to Interpreter before the source path.
	InterpreterArgs []string
	// Args are passed to the source after its path.
	Args []string
	// Stdin is copied to the standard input of the source until EOF or
	// until the container exits. If nil, the container has no standard
	// input. A read from Stdin can still be pending when the run returns.
	Stdin io.Reader
}

DockerSourceOptions holds the per-run inputs of RunSourceWithOptions.

type Filter

type Filter string
const (
	PrivateTmp              Filter = "PrivateTmp"
	PrivateNetwork          Filter = "PrivateNetwork"
	SELinuxContext          Filter = "SELinuxContext"
	NoNewPrivileges         Filter = "NoNewPrivileges"
	ProtectSystem           Filter = "ProtectSystem"
	ProtectHome             Filter = "ProtectHome"
	ProtectDevices          Filter = "ProtectDevices"
	CapabilityBoundingSet   Filter = "CapabilityBoundingSet"
	ReadWriteDirectories    Filter = "ReadWriteDirectories"
	ReadOnlyDirectories     Filter = "ReadOnlyDirectories"
	InaccessibleDirectories Filter = "InaccessibleDirectories"
	ProtectKernelTunables   Filter = "InaccessibleDirectories"
	ProtectKernelModules    Filter = "ProtectKernelModules"
	ProtectControlGroups    Filter = "ProtectControlGroups"
	RestrictNamespaces      Filter = "RestrictNamespaces"
	MemoryDenyWriteExecute  Filter = "MemoryDenyWriteExecute"
	RestrictRealtime        Filter = "RestrictRealtime"
	PrivateMounts           Filter = "PrivateMounts"
	DynamicUser             Filter = "DynamicUser"
	SystemCallFilter        Filter = "SystemCallFilter"
)

type Rule

type Rule struct {
	Filter Filter
	Arg    Arg
}

type Sandbox

type Sandbox interface {
	Run(ctx context.Context, cmd string) (*types.Result, error)
	RunScript(ctx context.Context, source string) (*types.Result, error)
	RunSource(ctx context.Context, source string, interpreter string) (*types.Result, error)
	Start() error
	Wait() error
	Stop() error
	Clear() error
}

func New

func New(ctx context.Context, config *Configuration) (Sandbox, error)

New sandbox with the given configuration

type SandboxDocker added in v0.1.1

type SandboxDocker struct {
	// contains filtered or unexported fields
}

SandboxDocker implements the Sandbox interface using Docker containers

func NewDockerSandbox added in v0.1.1

func NewDockerSandbox(ctx context.Context, config *DockerConfiguration) (*SandboxDocker, error)

NewDockerSandbox creates a new Docker-based sandbox

func (*SandboxDocker) Clear added in v0.1.1

func (s *SandboxDocker) Clear() error

Clear cleans up Docker resources (containers, images, etc.)

func (*SandboxDocker) Run added in v0.1.1

func (s *SandboxDocker) Run(ctx context.Context, cmd string) (*types.Result, error)

Run executes a command in the Docker container (synchronous execution)

func (*SandboxDocker) RunScript added in v0.1.1

func (s *SandboxDocker) RunScript(ctx context.Context, source string, interpreter string) (*types.Result, error)

RunScript executes a script in the Docker container

func (*SandboxDocker) RunSource added in v0.1.1

func (s *SandboxDocker) RunSource(ctx context.Context, source string, interpreter string) (*types.Result, error)

RunSource writes source code to a temporary file inside the container and executes it. The interpreter can include arguments, such as "python3 -u".

func (*SandboxDocker) RunSourceWithOptions added in v0.1.1

func (s *SandboxDocker) RunSourceWithOptions(
	ctx context.Context, source string, opts DockerSourceOptions,
) (*types.Result, error)

RunSourceWithOptions writes source code to a temporary file inside the container and executes it with the arguments and stdin in opts.

func (*SandboxDocker) Start added in v0.1.1

func (s *SandboxDocker) Start() error

Start is not implemented for Docker sandbox as it's stateless

func (*SandboxDocker) Stop added in v0.1.1

func (s *SandboxDocker) Stop() error

Stop is not implemented for Docker sandbox as it's stateless

func (*SandboxDocker) Wait added in v0.1.1

func (s *SandboxDocker) Wait() error

Wait is not implemented for Docker sandbox as it's stateless

type SandboxLinux

type SandboxLinux struct {
	Config *Configuration
	// contains filtered or unexported fields
}

Sandbox native on linux

func (*SandboxLinux) Clear

func (s *SandboxLinux) Clear() error

Clear the instance after stop

func (*SandboxLinux) Run

func (s *SandboxLinux) Run(ctx context.Context, cmd string) (*types.Result, error)

func (*SandboxLinux) RunScript added in v0.1.1

func (s *SandboxLinux) RunScript(ctx context.Context, source string) (*types.Result, error)

RunScript executes a script or source code in the sandbox

func (*SandboxLinux) RunSource added in v0.1.1

func (s *SandboxLinux) RunSource(ctx context.Context, source string, interpreter string) (*types.Result, error)

RunSource writes source code to a temporary file, executes it with proper permissions, and cleans up

func (*SandboxLinux) Start

func (s *SandboxLinux) Start() error

Start the instance

func (*SandboxLinux) Stop

func (s *SandboxLinux) Stop() error

Stop the instance

func (*SandboxLinux) Wait

func (s *SandboxLinux) Wait() error

Wait for the instance

type Symlink struct {
	Target string
	Link   string
}

Symlink represents a symlink to create in the sandbox

Jump to

Keyboard shortcuts

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