Documentation
¶
Overview ¶
Package sandbox provides standalone OS-level confinement for command execution under immutable, consumer-defined access profiles.
Harness's permission gates answer "may this tool call run?". This module answers "what can it touch once it runs?". The two compose: OS-level enforcement is what makes approved authority meaningful. Concretely, it provides immutable consumer-defined access profiles, single-spawn post-decision grants, honest achieved guarantees, and per-platform enforcement (Seatbelt on macOS; namespaces + Landlock + seccomp + nftables on Linux; restricted-token and installed-broker tiers on Windows). It does not import an approval system or read permission files. The Windows elevated tier remains unavailable until setup inspection can verify approved live runtime evidence from supported Windows 11 and Windows Server workers.
Initialization ¶
Consumers MUST call sandbox.Init() as the very first line of main():
func main() {
sandbox.Init()
// ... rest of program
}
On Linux, Init is the load-bearing re-exec dispatch entry point: every sandboxed spawn re-executes /proc/self/exe as a confinement helper (the moby/reexec pattern), and Init catches that re-exec before main() runs. On other platforms it is a no-op — but call it unconditionally so the code is portable. If it is not called, constructing an Executor with a Linux enforcement backend fails closed with ErrInitNotCalled rather than running commands unconfined. A sandboxed profile also fails closed with enforce.ErrUnavailable on a host without a production backend; direct execution exists only for an explicitly acknowledged Unconfined profile.
Index ¶
- Constants
- Variables
- func Init()
- func RemoveWindowsSandbox(ctx context.Context, config WindowsSetupConfig) error
- func SetupWindowsSandbox(ctx context.Context, config WindowsSetupConfig) error
- type Access
- type CompileReport
- type EgressRoute
- type EgressRouteResolver
- type Executor
- type ExecutorSet
- type ExecutorSetOption
- func WithEgressRoute(route EgressRoute) ExecutorSetOption
- func WithGrantTTL(duration time.Duration) ExecutorSetOption
- func WithMaxExecutors(max int) ExecutorSetOption
- func WithScratchRoot(path string) ExecutorSetOption
- func WithWindowsSandboxMode(mode WindowsSandboxMode) ExecutorSetOption
- func WithWindowsSandboxStateRoot(path string) ExecutorSetOption
- type Guarantees
- type Home
- type Isolation
- type LifetimeContainment
- type NetworkTarget
- type NetworkTargetDeniedError
- type PreparedProcess
- type Process
- type ProcessAccess
- type ProcessAccessKind
- type ProcessActivity
- type ProcessActivityKind
- type ProcessOptions
- type ProcessResult
- type ProcessSignal
- type ProcessStreamMode
- type Profile
- type ProfileConfig
- type ReportEntry
- type RootAccess
- type WindowsSandboxMode
- type WindowsSetupConfig
- type WindowsSetupProblem
- type WindowsSetupProblemCode
- type WindowsSetupStatus
Constants ¶
Access values.
const ( IsolatedHome = profile.IsolatedHome RealHome = profile.RealHome )
Home values.
const ( Sandboxed = profile.Sandboxed Unconfined = profile.Unconfined )
Isolation values.
const ( LevelNone = profile.LevelNone LevelDegraded = profile.LevelDegraded LevelFull = profile.LevelFull )
Achieved enforcement levels.
const ( GuaranteeProcessBoundary = profile.GuaranteeProcessBoundary GuaranteeWriteBoundary = profile.GuaranteeWriteBoundary GuaranteeReadBoundary = profile.GuaranteeReadBoundary GuaranteeEnvScrub = profile.GuaranteeEnvScrub GuaranteeNetworkBoundary = profile.GuaranteeNetworkBoundary GuaranteeAddressNetwork = profile.GuaranteeAddressNetwork GuaranteeResourceLimits = profile.GuaranteeResourceLimits GuaranteeTargetNetwork = profile.GuaranteeTargetNetwork )
Guarantee bits reported by a backend.
const ( WindowsAuto = windows.Auto WindowsRestrictedToken = windows.RestrictedToken WindowsElevated = windows.Elevated WindowsSetupProblemUnknown = windows.SetupProblemUnknown WindowsSetupProblemManifestMissing = windows.SetupProblemManifestMissing WindowsSetupProblemOwnerMismatch = windows.SetupProblemOwnerMismatch WindowsSetupProblemHostBinaryStale = windows.SetupProblemHostBinaryStale WindowsSetupProblemAccountMissing = windows.SetupProblemAccountMissing WindowsSetupProblemFirewallOverridden = windows.SetupProblemFirewallOverridden WindowsSetupProblemFirewallRuleChanged = windows.SetupProblemFirewallRuleChanged WindowsSetupProblemPortInUse = windows.SetupProblemPortInUse WindowsSetupProblemRuntimeBaselineGap = windows.SetupProblemRuntimeBaselineGap WindowsSetupProblemLeaseRecoveryPending = windows.SetupProblemLeaseRecoveryPending WindowsSetupProblemProtocolMismatch = windows.SetupProblemProtocolMismatch )
const ( GrantClassCommandStart = exec.GrantClassCommandStart GrantClassNetworkProxyTarget = exec.GrantClassNetworkProxyTarget GrantClassNetworkBroad = exec.GrantClassNetworkBroad GrantClassFilesystemPathRead = exec.GrantClassFilesystemPathRead GrantClassFilesystemTreeRead = exec.GrantClassFilesystemTreeRead GrantClassFilesystemHostRead = exec.GrantClassFilesystemHostRead GrantClassFilesystemPathWrite = exec.GrantClassFilesystemPathWrite GrantClassFilesystemTreeWrite = exec.GrantClassFilesystemTreeWrite GrantClassFilesystemHostWrite = exec.GrantClassFilesystemHostWrite )
Grant enforcement-class identifiers. These string VALUES are the shipped wire contract between this module and whatever mints grants against it.
const ( ProcessAccessReadOnly = exec.ProcessAccessReadOnly ProcessAccessScopedWrite = exec.ProcessAccessScopedWrite ProcessAccessBroadWrite = exec.ProcessAccessBroadWrite )
ProcessAccessKind values.
const ( ProcessActivityWrite = exec.ProcessActivityWrite ProcessActivityBroadWrite = exec.ProcessActivityBroadWrite )
ProcessActivityKind values.
const ( ProcessStreamModePipes = exec.ProcessStreamModePipes ProcessStreamModePTY = exec.ProcessStreamModePTY )
ProcessStreamMode values.
const ( ProcessSignalInterrupt = exec.ProcessSignalInterrupt ProcessSignalTerminate = exec.ProcessSignalTerminate ProcessSignalKill = exec.ProcessSignalKill )
ProcessSignal values.
const ( LifetimeContainmentUnspecified = exec.LifetimeContainmentUnspecified LifetimeContainmentEnforced = exec.LifetimeContainmentEnforced LifetimeContainmentBestEffort = exec.LifetimeContainmentBestEffort )
LifetimeContainment values.
Variables ¶
var ( ErrWindowsSetupRequired = windows.ErrSetupRequired ErrWindowsSetupStale = windows.ErrSetupStale ErrWindowsElevationRequired = windows.ErrElevationRequired )
var ( ErrOutputLimit = exec.ErrOutputLimit ErrExecutorLimit = exec.ErrExecutorLimit ErrExecutorSetClosed = exec.ErrExecutorSetClosed ErrExecutorClosed = exec.ErrExecutorClosed )
Executor lifecycle sentinels.
var ( ErrGrantMalformed = exec.ErrGrantMalformed ErrGrantBadMAC = exec.ErrGrantBadMAC ErrGrantExpired = exec.ErrGrantExpired ErrGrantWrongCommand = exec.ErrGrantWrongCommand ErrGrantWrongExecution = exec.ErrGrantWrongExecution ErrGrantWrongWorkingDirectory = exec.ErrGrantWrongWorkingDirectory ErrGrantProfileMismatch = exec.ErrGrantProfileMismatch ErrGrantGuaranteeMismatch = exec.ErrGrantGuaranteeMismatch ErrGrantRouteMismatch = exec.ErrGrantRouteMismatch ErrGrantTargetChanged = exec.ErrGrantTargetChanged ErrGrantReplay = exec.ErrGrantReplay ErrGrantRequired = exec.ErrGrantRequired ErrGrantDenied = exec.ErrGrantDenied ErrGrantUnsupported = exec.ErrGrantUnsupported )
Grant sentinels. Each is the single value raised anywhere in the module, so errors.Is answers the same regardless of which layer refused.
var ( ErrProcessClosed = exec.ErrProcessClosed ErrProcessAlreadyStarted = exec.ErrProcessAlreadyStarted ErrProcessTTYUnsupported = exec.ErrProcessTTYUnsupported // ErrProcessConPTYUnavailable reports that a TTY-backed process request // on Windows resolved to a host that does not export the // CreatePseudoConsole API (Windows 10 1809+ / Windows Server 2019+ // only) — a runtime capability gap distinct from // ErrProcessTTYUnsupported's own compile-time/backend-dispatch checks. // See exec.ErrProcessConPTYUnavailable's own doc comment // (internal/exec/process_errors.go) for the full distinction. ErrProcessStdinClosed = exec.ErrProcessStdinClosed // PreparedProcess.Start) spawn cannot be given an exact, kernel-enforced // process-tree teardown proof before it starts, so it was rejected before // any child process was created rather than run with only a best-effort // process-group signal-and-poll fallback. Its concrete remaining caller // is Linux, returned only when Rung 2 selects a spawn with no delegated // cgroup v2 pids ancestor available. Darwin no longer returns this: a // real Seatbelt-confined Supervised spawn instead receives a best-effort // process-tree teardown prover, with the downgrade from a kernel-enforced // proof reported per spawn through LifetimeContainment (see // Process.LifetimeContainment and docs/lifetime-containment.md). ErrLifetimeContainmentUnavailable = enforce.ErrLifetimeContainmentUnavailable )
Process/PreparedProcess sentinels.
var ErrEgressRouteDenied = network.ErrRouteDenied
ErrEgressRouteDenied reports that no configured route may carry a target.
var ErrInvalidProfile = profile.ErrInvalidProfile
ErrInvalidProfile identifies malformed, unconstructed, or inconsistent profiles. Details are wrapped for diagnostics; callers may use errors.Is.
var ErrNetworkTargetDenied = network.ErrTargetDenied
ErrNetworkTargetDenied reports that the proxy refused a network target.
ErrSandboxUnavailable reports that no production OS confinement backend is available on this host, so a Sandboxed profile cannot be honoured.
Functions ¶
func Init ¶
func Init()
Init is the re-exec dispatch entry point (SPEC §6). Consumers MUST call it as the very first line of main(), before any goroutine, file descriptor, or thread state is established:
func main() {
sandbox.Init()
// ... rest of program
}
On Linux it inspects the reserved re-exec sentinels and dispatches a stage-2 helper or namespace-probe child (the moby/reexec pattern, §7.2); in a normal process it records that it ran and returns immediately. The mechanism lives in internal/linux; Init stays at the root import path because that is where every consumer's main() calls it.
func RemoveWindowsSandbox ¶
func RemoveWindowsSandbox(ctx context.Context, config WindowsSetupConfig) error
func SetupWindowsSandbox ¶
func SetupWindowsSandbox(ctx context.Context, config WindowsSetupConfig) error
Types ¶
type CompileReport ¶
type CompileReport = profile.CompileReport
CompileReport records enforced, narrowed, and unavailable features.
type EgressRoute ¶
EgressRoute is how a sandboxed process reaches the network.
func NewDirectEgressRoute ¶
func NewDirectEgressRoute() (EgressRoute, error)
NewDirectEgressRoute builds the route that dials targets itself.
func NewUpstreamEgressRoute ¶
func NewUpstreamEgressRoute(rawURL string, trustedAddressGuarantee bool) (EgressRoute, error)
NewUpstreamEgressRoute builds a route that hands targets to an upstream proxy.
type EgressRouteResolver ¶
type EgressRouteResolver = network.RouteResolver
EgressRouteResolver selects a route per target.
func NewEgressRouteResolver ¶
func NewEgressRouteResolver(routes []EgressRoute, selector func(context.Context, NetworkTarget) string) (*EgressRouteResolver, error)
NewEgressRouteResolver builds a resolver over the supplied routes.
type ExecutorSet ¶
type ExecutorSet = exec.ExecutorSet
ExecutorSet owns per-key executors, their grant keys, and isolated HOMEs.
func NewExecutorSet ¶
func NewExecutorSet(p *Profile, options ...ExecutorSetOption) (*ExecutorSet, error)
NewExecutorSet creates one owner-only child beneath a required scratch root.
type ExecutorSetOption ¶
type ExecutorSetOption = exec.ExecutorSetOption
ExecutorSetOption configures executor ownership and resource limits.
func WithEgressRoute ¶
func WithEgressRoute(route EgressRoute) ExecutorSetOption
WithEgressRoute configures the explicit route used by target-scoped grants.
func WithGrantTTL ¶
func WithGrantTTL(duration time.Duration) ExecutorSetOption
WithGrantTTL sets the maximum lifetime of grants minted by every executor.
func WithMaxExecutors ¶
func WithMaxExecutors(max int) ExecutorSetOption
WithMaxExecutors sets the hard number of memoized executor identities.
func WithScratchRoot ¶
func WithScratchRoot(path string) ExecutorSetOption
WithScratchRoot supplies the caller-owned parent for the set's owned child.
func WithWindowsSandboxMode ¶
func WithWindowsSandboxMode(mode WindowsSandboxMode) ExecutorSetOption
WithWindowsSandboxMode selects the Windows confinement tier.
func WithWindowsSandboxStateRoot ¶
func WithWindowsSandboxStateRoot(path string) ExecutorSetOption
WithWindowsSandboxStateRoot selects the Windows elevated installation root.
type Guarantees ¶
type Guarantees = profile.Guarantees
Guarantees reports properties actually enforced by the selected backend.
type LifetimeContainment ¶
type LifetimeContainment = exec.LifetimeContainment
LifetimeContainment reports the process-tree teardown contract a Supervised spawn actually received (enforced / best-effort / unspecified). See Process.LifetimeContainment.
type NetworkTarget ¶
NetworkTarget is one normalized transport/host/port egress destination.
func ParseNetworkTarget ¶
func ParseNetworkTarget(raw string) (NetworkTarget, error)
ParseNetworkTarget parses a normalized "transport:host:port" target.
type NetworkTargetDeniedError ¶
type NetworkTargetDeniedError = network.TargetDeniedError
NetworkTargetDeniedError reports a spawn that ran but was denied a target.
type PreparedProcess ¶
type PreparedProcess = exec.PreparedProcess
PreparedProcess is a validated, single-use process start.
type ProcessAccess ¶
type ProcessAccess = exec.ProcessAccess
ProcessAccess is the authoritative, immutable description of a prepared process's workspace access.
type ProcessAccessKind ¶
type ProcessAccessKind = exec.ProcessAccessKind
ProcessAccessKind classifies ProcessAccess.
type ProcessActivity ¶
type ProcessActivity = exec.ProcessActivity
ProcessActivity reports one unit of workspace activity from a running process.
type ProcessActivityKind ¶
type ProcessActivityKind = exec.ProcessActivityKind
ProcessActivityKind classifies ProcessActivity.
type ProcessOptions ¶
type ProcessOptions = exec.ProcessOptions
ProcessOptions describes one asynchronous process admission request.
type ProcessResult ¶
type ProcessResult = exec.ProcessResult
ProcessResult is the terminal result of an asynchronous process.
type ProcessSignal ¶
type ProcessSignal = exec.ProcessSignal
ProcessSignal is a portable process-tree signal request.
type ProcessStreamMode ¶
type ProcessStreamMode = exec.ProcessStreamMode
ProcessStreamMode describes a running process's stream topology (distinct pipes or one combined PTY stream).
type Profile ¶
Profile is an immutable, normalized access profile.
func NewProfile ¶
func NewProfile(config ProfileConfig) (*Profile, error)
NewProfile validates, canonicalizes, and owns a copy of config.
type ProfileConfig ¶
type ProfileConfig = profile.ProfileConfig
ProfileConfig contains every consumer-selected sandbox authority value.
type ReportEntry ¶
type ReportEntry = profile.ReportEntry
ReportEntry records how one requested feature was compiled by a backend.
type RootAccess ¶
type RootAccess = profile.RootAccess
RootAccess describes read and write authority for one additional root.
type WindowsSandboxMode ¶
type WindowsSandboxMode = windows.SandboxMode
Windows sandbox selection and elevated setup vocabulary.
type WindowsSetupConfig ¶
type WindowsSetupConfig = windows.SetupConfig
Windows sandbox selection and elevated setup vocabulary.
type WindowsSetupProblem ¶
type WindowsSetupProblem = windows.SetupProblem
Windows sandbox selection and elevated setup vocabulary.
type WindowsSetupProblemCode ¶
type WindowsSetupProblemCode = windows.WindowsSetupProblemCode
Windows sandbox selection and elevated setup vocabulary.
type WindowsSetupStatus ¶
type WindowsSetupStatus = windows.SetupStatus
Windows sandbox selection and elevated setup vocabulary.
func InspectWindowsSandbox ¶
func InspectWindowsSandbox(ctx context.Context, config WindowsSetupConfig) (WindowsSetupStatus, error)
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
sandbox-host
command
|
|
|
internal
|
|
|
safetext
Package safetext holds the single predicate every untrusted single-line identifier in this module is validated against — grant fields, execution IDs, and proxy credentials alike.
|
Package safetext holds the single predicate every untrusted single-line identifier in this module is validated against — grant fields, execution IDs, and proxy credentials alike. |
|
testsupport
Fixture policies for backend tests.
|
Fixture policies for backend tests. |
|
windows
Package windows owns the configuration and setup vocabulary for the Windows sandbox backends.
|
Package windows owns the configuration and setup vocabulary for the Windows sandbox backends. |
|
winpath
Package winpath provides fail-closed, handle-derived Windows path identity.
|
Package winpath provides fail-closed, handle-derived Windows path identity. |
|
pkg
|
|
|
sandboxtest
Package sandboxtest is a reusable conformance suite for sandbox executors, modelled on the storekit `storetest` pattern: a consumer supplies a factory that builds an executor, and RunSuite asserts the core sandbox invariants hold against it.
|
Package sandboxtest is a reusable conformance suite for sandbox executors, modelled on the storekit `storetest` pattern: a consumer supplies a factory that builds an executor, and RunSuite asserts the core sandbox invariants hold against it. |
|
spikes
|
|