sandbox

package
v0.107.20 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaskedDirs added in v0.107.16

func MaskedDirs() []string

MaskedDirs are the credential directories hidden from sandboxed commands.

func ProtectedPaths added in v0.107.16

func ProtectedPaths(root string) []string

ProtectedPaths are the files under a workspace that a later session trusts without asking: project instructions and prompts, and git hooks.

func RootFromEnv

func RootFromEnv() string

func WithPolicy

func WithPolicy(ctx context.Context, policy *Policy) context.Context

Types

type Capability added in v0.107.16

type Capability struct {
	Supported      bool   `json:"supported"`
	Mechanism      string `json:"mechanism"`
	Platform       string `json:"platform"`
	NetworkControl bool   `json:"network_control"`
	ReadMasking    bool   `json:"read_masking"`
	Reason         string `json:"reason,omitempty"`
}

Capability reports whether this machine can confine a run's commands.

func Probe added in v0.107.16

func Probe() Capability

Probe checks the platform mechanism once per process by running a trivial confined command, so a binary that exists but cannot start (no user namespaces in a container) reports unsupported instead of failing later.

type Policy

type Policy struct {
	Mode     string
	Backend  string
	Root     string
	Network  bool
	Writable []string
	ReadOnly []string
	// Masked directories are neither readable nor writable inside the sandbox
	// (credentials, the backend's own data). A workspace root inside one of them
	// stays usable; a root that encloses one is refused.
	Masked []string
	// Protected paths stay readable but not writable, even inside a writable
	// root: project instructions and hooks that a later, unsandboxed session
	// would trust.
	Protected []string
}

func ForRun added in v0.107.16

func ForRun(base *Policy, req RunRequest) (*Policy, error)

ForRun builds the policy for a run that asked for the workspace sandbox. A configured policy (base) is only ever tightened: its roots stay as they are, network stays off when either side turns it off, and the masks and protected paths are added. Without a configured policy the run's roots are the grants. The result fails closed: when the machine cannot confine commands an error is returned instead of a policy.

func FromContext

func FromContext(ctx context.Context) *Policy

func New

func New(mode, backend, root string, network bool, writable, readOnly []string) *Policy

func (*Policy) Enabled

func (p *Policy) Enabled() bool

func (*Policy) ForRoot

func (p *Policy) ForRoot(root string) *Policy

func (*Policy) Wrap

func (p *Policy) Wrap(ctx context.Context, cmd *exec.Cmd) (*exec.Cmd, error)

Wrap returns cmd confined by the policy. It fails rather than run the command unconfined when the platform mechanism is missing or the root is unsafe.

type RunRequest added in v0.107.16

type RunRequest struct {
	Root string
	// Writable lists the run's other writable workspace roots.
	Writable []string
	Network  bool
	// Masked and Protected extend the defaults (MaskedDirs, ProtectedPaths).
	Masked    []string
	Protected []string
}

RunRequest is a run's request to confine its commands to the workspace.

Jump to

Keyboard shortcuts

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