sandbox

package
v0.0.0-...-75ec8e3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package sandbox provides filesystem sandboxing capabilities using Linux Landlock. On Linux systems with Landlock support (kernel 5.13+), this restricts shell command execution to specific directories with configurable access permissions. On non-Linux systems or when Landlock is unavailable, operations proceed without sandboxing.

Package sandbox provides filesystem sandboxing capabilities using Linux Landlock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessLevel

type AccessLevel int

AccessLevel represents the type of filesystem access granted to a path.

const (
	// AccessReadOnly grants read-only access (read files, list directories)
	AccessReadOnly AccessLevel = iota
	// AccessReadWrite grants read and write access
	AccessReadWrite
	// AccessExecute grants execute access for binaries
	AccessExecute
)

type AsyncAuthorizationCallback

type AsyncAuthorizationCallback func(request RequestedDirectory, responseChan chan<- AuthorizationDecision)

AsyncAuthorizationCallback is a function that handles authorization asynchronously. It's called in a goroutine and should send the decision to the provided channel.

type AuthorizationCallback

type AuthorizationCallback func(request RequestedDirectory) AuthorizationDecision

AuthorizationCallback is a function that requests user authorization for a directory access request. It returns the user's decision. This callback should be non-blocking - it should return immediately with DecisionDenied if the request is queued for user input.

type AuthorizationDecision

type AuthorizationDecision int

AuthorizationDecision represents the user's decision on directory authorization.

const (
	// DecisionDenied denies the request for this session
	DecisionDenied AuthorizationDecision = iota
	// DecisionApprovedSession approves for this session only
	DecisionApprovedSession
	// DecisionApprovedWorkspace approves and persists for this workspace
	DecisionApprovedWorkspace
)

type AuthorizationResult

type AuthorizationResult struct {
	Decision   AuthorizationDecision
	Path       string
	Access     AccessLevel
	Persistent bool // Whether this should be persisted to workspace config
}

AuthorizationResult contains the result of an authorization request.

type DirectoryPermission

type DirectoryPermission struct {
	Path   string
	Access AccessLevel
}

DirectoryPermission represents a directory path with its access level.

type LandlockSandbox

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

LandlockSandbox provides filesystem sandboxing using Linux Landlock LSM.

func NewLandlockSandbox

func NewLandlockSandbox(workspaceDir string, cfg *SandboxConfig) *LandlockSandbox

NewLandlockSandbox creates a new Landlock sandbox for the given workspace. If config is provided, custom paths are added and sandbox can be disabled.

func (*LandlockSandbox) AddAuthorizedPath

func (s *LandlockSandbox) AddAuthorizedPath(path string, access AccessLevel)

AddAuthorizedPath adds a directory path that has been authorized by the user.

func (*LandlockSandbox) Disable

func (s *LandlockSandbox) Disable()

Disable disables the sandbox.

func (*LandlockSandbox) Enable

func (s *LandlockSandbox) Enable()

Enable enables the sandbox if available.

func (*LandlockSandbox) GetAllowedPaths

func (s *LandlockSandbox) GetAllowedPaths() []DirectoryPermission

GetAllowedPaths returns the current allowed paths.

func (*LandlockSandbox) GetWorkspaceDir

func (s *LandlockSandbox) GetWorkspaceDir() string

GetWorkspaceDir returns the workspace directory.

func (*LandlockSandbox) IsEnabled

func (s *LandlockSandbox) IsEnabled() bool

IsEnabled returns whether sandboxing is currently enabled.

func (*LandlockSandbox) Restrict

func (s *LandlockSandbox) Restrict() error

Restrict applies Landlock restrictions to the current process. This should be called before executing shell commands.

func (*LandlockSandbox) SetAdditionalPaths

func (s *LandlockSandbox) SetAdditionalPaths(paths []DirectoryPermission)

SetAdditionalPaths sets the additional authorized paths.

func (*LandlockSandbox) WrapCommand

func (s *LandlockSandbox) WrapCommand(cmd *exec.Cmd) error

WrapCommand wraps an exec.Cmd with Landlock restrictions. This modifies the command to run with restricted filesystem access.

type Manager

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

Manager manages the Landlock sandbox for the application.

func NewManager

func NewManager(cfg *config.Config, workspaceDir string) *Manager

NewManager creates a new sandbox manager.

func (*Manager) ApplyDecision

func (m *Manager) ApplyDecision(path string, access AccessLevel, decision AuthorizationDecision)

ApplyDecision applies an authorization decision from the TUI. This is called when the user responds to the directory access dialog.

func (*Manager) Disable

func (m *Manager) Disable()

Disable disables the sandbox.

func (*Manager) Enable

func (m *Manager) Enable()

Enable enables the sandbox.

func (*Manager) GetAllowedPaths

func (m *Manager) GetAllowedPaths() []DirectoryPermission

GetAllowedPaths returns all currently allowed paths.

func (*Manager) GetSandbox

func (m *Manager) GetSandbox() *LandlockSandbox

GetSandbox returns the underlying sandbox instance.

func (*Manager) GetSessionPaths

func (m *Manager) GetSessionPaths() []DirectoryPermission

GetSessionPaths returns paths approved for this session only.

func (*Manager) IsEnabled

func (m *Manager) IsEnabled() bool

IsEnabled returns whether sandboxing is enabled.

func (*Manager) LoadWorkspaceApprovals

func (m *Manager) LoadWorkspaceApprovals()

LoadWorkspaceApprovals loads previously approved paths from the workspace config.

func (*Manager) RequestMultiplePaths

func (m *Manager) RequestMultiplePaths(requests []RequestedDirectory) map[string]AuthorizationDecision

RequestMultiplePaths requests access to multiple directory paths. Returns a map of path -> decision for each requested path.

func (*Manager) RequestPathAccess

func (m *Manager) RequestPathAccess(path string, access AccessLevel, description string) AuthorizationDecision

RequestPathAccess requests access to an additional directory path. It checks workspace-approved paths first, then prompts for authorization if needed.

func (*Manager) SetAsyncAuthorizationCallback

func (m *Manager) SetAsyncAuthorizationCallback(cb AsyncAuthorizationCallback)

SetAsyncAuthorizationCallback sets the async callback function for requesting authorization. The async callback is preferred if both are set.

func (*Manager) SetAuthorizationCallback

func (m *Manager) SetAuthorizationCallback(cb AuthorizationCallback)

SetAuthorizationCallback sets the callback function for requesting authorization.

type PackageManagerConfig

type PackageManagerConfig struct {
	Name        string
	EnvVars     []string // Environment variables that may contain paths
	HomeSubdirs []string // Subdirectories under HOME
	SystemPaths []string // System-wide paths
	GlobPaths   []string // Paths with glob patterns (under HOME)
}

PackageManagerConfig defines paths for a specific package manager

type RequestedDirectory

type RequestedDirectory struct {
	Path        string
	Access      AccessLevel
	Description string // Optional description of why access is needed
}

RequestedDirectory represents a directory request from the LLM that needs user authorization.

type SandboxConfig

type SandboxConfig struct {
	AdditionalReadOnlyPaths  []string
	AdditionalReadWritePaths []string
	DisableSandbox           bool
	BestEffort               bool
}

SandboxConfig holds configuration for additional sandbox paths. This is a simplified version of config.SandboxConfig to avoid import cycles.

Jump to

Keyboard shortcuts

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