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 ¶
- type AccessLevel
- type AsyncAuthorizationCallback
- type AuthorizationCallback
- type AuthorizationDecision
- type AuthorizationResult
- type DirectoryPermission
- type LandlockSandbox
- func (s *LandlockSandbox) AddAuthorizedPath(path string, access AccessLevel)
- func (s *LandlockSandbox) Disable()
- func (s *LandlockSandbox) Enable()
- func (s *LandlockSandbox) GetAllowedPaths() []DirectoryPermission
- func (s *LandlockSandbox) GetWorkspaceDir() string
- func (s *LandlockSandbox) IsEnabled() bool
- func (s *LandlockSandbox) Restrict() error
- func (s *LandlockSandbox) SetAdditionalPaths(paths []DirectoryPermission)
- func (s *LandlockSandbox) WrapCommand(cmd *exec.Cmd) error
- type Manager
- func (m *Manager) ApplyDecision(path string, access AccessLevel, decision AuthorizationDecision)
- func (m *Manager) Disable()
- func (m *Manager) Enable()
- func (m *Manager) GetAllowedPaths() []DirectoryPermission
- func (m *Manager) GetSandbox() *LandlockSandbox
- func (m *Manager) GetSessionPaths() []DirectoryPermission
- func (m *Manager) IsEnabled() bool
- func (m *Manager) LoadWorkspaceApprovals()
- func (m *Manager) RequestMultiplePaths(requests []RequestedDirectory) map[string]AuthorizationDecision
- func (m *Manager) RequestPathAccess(path string, access AccessLevel, description string) AuthorizationDecision
- func (m *Manager) SetAsyncAuthorizationCallback(cb AsyncAuthorizationCallback)
- func (m *Manager) SetAuthorizationCallback(cb AuthorizationCallback)
- type PackageManagerConfig
- type RequestedDirectory
- type SandboxConfig
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) 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 ¶
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) 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) 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.