sandboxcfg

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 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

Overview

Package sandboxcfg persists and merges the user-facing sandbox.json configuration layer that decides *what* the kernel boundary allows once a process runs (mode, availability locks, unsandboxed escape hatches, and filesystem/network overrides).

It mirrors the two-scope layout of the permissions package (permissions.json decides *whether* a tool call requires approval; sandbox.json decides *what* the OS isolation permits), keeping authorization and isolation independent:

  • global: $XDG_CONFIG_HOME/tasksmith/sandbox.json
  • project: $XDG_DATA_HOME/tasksmith/workspaces/<hash>/sandbox.json

Effective settings follow the workspace trust boundary: repository-committed files can never widen these scopes, boolean knobs inherit across scopes via pointer optionality, and the global scope holds monotonic locks (a global "failIfUnavailable": true or "allowUnsandboxed": false can never be relaxed by the project scope).

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidConfig = errors.New("sandboxcfg: invalid configuration")
	ErrInvalidScope  = errors.New("sandboxcfg: unsupported scope")
	ErrInvalidValue  = errors.New("sandboxcfg: invalid sandbox setting")
)

Sentinel errors returned by the sandboxcfg package.

Functions

func ResolveUserPath

func ResolveUserPath(scope api.PermissionScope, raw, workDir string) (string, error)

ResolveUserPath canonicalizes one user-authored path from sandbox.json for the given scope: "~" and "~/..." expand to the user's home directory, and project scope additionally resolves relative paths against the workspace root. Global scope rejects relative paths other than "~/..." because a user-wide configuration file has no meaningful anchor directory to resolve them against.

func Validate

func Validate(scope api.PermissionScope, workDir string, settings api.SandboxSettings) error

Validate checks a scope's settings before persistence: modes must be known values, filesystem paths must be resolvable for the scope, and network domain patterns must be exact hosts or "*." wildcard suffixes.

Types

type Config

type Config struct {
	// WorkDir is the workspace root used to resolve relative project paths and
	// to anchor the built-in security floor (credential masks, protected
	// workspace write paths).
	WorkDir string

	// Restricted reports whether the workspace is currently untrusted. It
	// forces allowUnsandboxed false in Effective() and can be updated later
	// via Manager.SetRestricted.
	Restricted bool

	// GlobalPath optionally overrides $XDG_CONFIG_HOME/tasksmith/sandbox.json
	// (tests).
	GlobalPath string

	// ProjectPath optionally overrides
	// $XDG_DATA_HOME/tasksmith/workspaces/<hash>/sandbox.json (tests).
	ProjectPath string
}

Config configures the per-workspace sandbox Manager.

type Effective

type Effective struct {
	// Settings is the merged user-facing configuration (what clients display).
	Settings api.SandboxSettings

	// Mode is the configured default backend ("native"/"local"), before the
	// host availability probe. Use ResolveMode for the enforceable backend.
	Mode api.SandboxMode
	// FailIfUnavailable requests hard failure instead of degrading to local
	// isolation when kernel sandboxing is unavailable.
	FailIfUnavailable bool
	// AllowUnsandboxed gates per-command unsandboxed execution. Forced false
	// in restricted workspaces and locked false by a global "false".
	AllowUnsandboxed bool
	// AutoAllowBash auto-approves safe sandboxed bash plans (consumed by the
	// permission engine).
	AutoAllowBash bool
	// ExcludedCommands holds command patterns exempted from the kernel
	// sandbox (consumed by the bash tool policy).
	ExcludedCommands []string

	// DeniedReadPaths is the credential read-masking floor merged with user
	// denyRead entries, minus any narrower user allowRead re-opens.
	DeniedReadPaths []string
	// AllowReadPaths re-opens subtrees inside a DeniedReadPaths mask.
	AllowReadPaths []string
	// ExtraWritePaths are writable directories outside the workspace root.
	ExtraWritePaths []string
	// DeniedWritePaths are protected paths that stay read-only even inside a
	// writable root; the built-in floor can never be removed by user config.
	DeniedWritePaths []string

	// Network carries the merged subprocess network posture.
	Network api.SandboxNetworkSettings

	// WorkDir is the workspace root the path lists were resolved against.
	WorkDir string
}

Effective is the fully resolved sandbox posture for one workspace: the merged user settings plus the canonical kernel path lists a session sandbox must apply.

func (Effective) Clone

func (e Effective) Clone() Effective

Clone returns a deep copy of the effective posture.

func (Effective) FilesystemPolicy

func (e Effective) FilesystemPolicy() sandbox.FilesystemPolicy

FilesystemPolicy renders the effective posture as the kernel path policy a sandbox.Sandbox enforces.

func (Effective) Overlay

Overlay layers the user-configured posture on top of a session's built-in floor policy (credential masks, protected writes, linked-worktree extras). All four lists are unioned so nothing a floor protects can be dropped by a configuration mistake; a user allowRead nested inside a floor mask survives as an allow entry and is re-opened by the kernel's breadth-ordered rule merge, while TaskSmith's own secret stores were already stripped from the user's allow list by the merge engine.

func (Effective) ResolveMode

func (e Effective) ResolveMode(requested api.SandboxMode) (api.SandboxMode, error)

ResolveMode maps a session's requested backend onto the backend this host can enforce, honoring the effective failIfUnavailable lock: with the lock active, requesting (or defaulting to) native on a host without kernel sandboxing returns sandbox.ErrNativeUnavailable instead of degrading.

func (Effective) ResolvedPaths

func (e Effective) ResolvedPaths() api.SandboxResolvedPaths

ResolvedPaths renders the effective posture for client inspection.

type Manager

type Manager interface {
	// WorkDir returns the canonical workspace root the manager is bound to.
	WorkDir() string

	// SetRestricted updates the trust posture reflected by Effective().
	SetRestricted(restricted bool)

	// Restricted reports whether the workspace is currently untrusted.
	Restricted() bool

	// WithRestricted returns a view sharing the same underlying sandbox.json
	// store and lock while tracking an independent restricted posture (for
	// sibling subproject runtimes under a shared workspace root).
	WithRestricted(restricted bool) Manager

	// Get returns the stored [api.SandboxSettings] for ScopeProject or
	// ScopeGlobal. A missing file yields zero settings.
	Get(scope api.PermissionScope) (api.SandboxSettings, error)

	// Set validates and atomically overwrites the stored settings for
	// ScopeProject or ScopeGlobal.
	Set(scope api.PermissionScope, settings api.SandboxSettings) error

	// Effective merges global and project scopes over the built-in security
	// floor following the workspace precedence rules.
	Effective() (Effective, error)

	// EffectiveFor merges the scopes like Effective but resolves project-
	// relative paths and the built-in security floor against the given work
	// directory (e.g. a subagent's isolated worktree root). An empty workDir
	// falls back to the manager's workspace root.
	EffectiveFor(workDir string) (Effective, error)
}

Manager coordinates global and project sandbox.json persistence and computes the effective per-workspace settings.

func New

func New(cfg Config) (Manager, error)

New constructs a Manager bound to the given workspace root.

Jump to

Keyboard shortcuts

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