Help us shape the future of Go! Take the 2026 Go Developer Survey

sandbox

package
v7.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

-- internal/sandbox/manager.go --

-- internal/sandbox/types.go --

Index

Constants

View Source
const (
	EnvTimeout   = "SFW_SANDBOX_TIMEOUT"    // a Go duration, such as 20m
	EnvMemoryMiB = "SFW_SANDBOX_MEMORY_MIB" // RLIMIT_AS of each process
	EnvTmpMiB    = "SFW_SANDBOX_TMP_MIB"    // size of /tmp and RLIMIT_FSIZE
)

Environment variables that override the default Limits.

View Source
const (
	EnvSandboxID = "SFW_SANDBOX_ID"
	// EnvTypeCache is diff.TypeCacheEnvVar: "rw:DIR" or "ro:DIR" names the
	// persistent type cache.
	EnvTypeCache = "SFW_TYPE_CACHE"

	RuntimeBinary = "runsc"
)

Variables

View Source
var DefaultLimits = Limits{Timeout: 20 * time.Minute, MemoryMiB: defaultMemoryMiB(), TmpMiB: 2048}

DefaultLimits are the Limits without overrides. The address space is three quarters of the host's memory, so a run fails on its own limit before the host's OOM killer takes the machine.

Functions

func IsSandboxed

func IsSandboxed() bool

Checks if the current process is already running inside the sandbox.

func Run

func Run(ctx context.Context, cfg Config, stdout, stderr io.Writer) error

Run executes the current binary (self) inside a gVisor sandbox, within the Limits the environment sets (see LimitsFromEnv). A run that times out fails.

Types

type Capabilities

type Capabilities struct {
	Bounding    []string `json:"bounding"`
	Effective   []string `json:"effective"`
	Inheritable []string `json:"inheritable"`
	Permitted   []string `json:"permitted"`
	Ambient     []string `json:"ambient"`
}

type Config

type Config struct {
	Args    []string // Arguments for the internal worker
	Mounts  []string // List of host paths to bind mount (read only)
	WorkDir string   // Working directory inside the sandbox
}

Config defines the execution parameters for the sandboxed process.

type IDMapping

type IDMapping struct {
	ContainerID int `json:"containerID"`
	HostID      int `json:"hostID"`
	Size        int `json:"size"`
}

type Limits added in v7.5.0

type Limits struct {
	// Timeout ends the run, which then fails.
	Timeout time.Duration
	// MemoryMiB is each process's address space (RLIMIT_AS). Go maps more
	// than it touches: a deps diff of helm v4 peaks at 8.9 GiB mapped for
	// 7.5 GiB resident.
	MemoryMiB uint64
	// TmpMiB is the size of the /tmp tmpfs, which holds the build cache and
	// a copied signature database, and the largest file a process may
	// write (RLIMIT_FSIZE). tmpfs memory counts toward no rlimit.
	TmpMiB uint64
}

Limits bound one sandboxed run. gVisor's sentry enforces the rlimits itself, without cgroups, but per process: the sandbox's processes together, and the sentry's own memory, are bounded only by the host.

func LimitsFromEnv added in v7.5.0

func LimitsFromEnv() (Limits, error)

LimitsFromEnv returns DefaultLimits with the overrides the environment sets. A value that does not parse, or is too small, is an error, not the default.

type Linux

type Linux struct {
	Namespaces  []Namespace `json:"namespaces"`
	UIDMappings []IDMapping `json:"uidMappings"`
	GIDMappings []IDMapping `json:"gidMappings"`
}

type Mount

type Mount struct {
	Destination string   `json:"destination"`
	Type        string   `json:"type"`
	Source      string   `json:"source"`
	Options     []string `json:"options"`
}

type Namespace

type Namespace struct {
	Type string `json:"type"`
}

type Process

type Process struct {
	User            User          `json:"user"`
	Args            []string      `json:"args"`
	Env             []string      `json:"env"`
	Cwd             string        `json:"cwd"`
	Capabilities    *Capabilities `json:"capabilities"`
	Rlimits         []Rlimit      `json:"rlimits"`
	NoNewPrivileges bool          `json:"noNewPrivileges"`
}

type Rlimit

type Rlimit struct {
	Type string `json:"type"`
	Hard uint64 `json:"hard"`
	Soft uint64 `json:"soft"`
}

type Root

type Root struct {
	Path     string `json:"path"`
	Readonly bool   `json:"readonly"`
}

type Spec

type Spec struct {
	Version string   `json:"ociVersion"`
	Process *Process `json:"process"`
	Root    *Root    `json:"root"`
	Mounts  []Mount  `json:"mounts"`
	Linux   *Linux   `json:"linux"`
}

type User

type User struct {
	UID int `json:"uid"`
	GID int `json:"gid"`
}

Jump to

Keyboard shortcuts

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