runtime

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyAppArmor

func ApplyAppArmor(profileName string) error

ApplyAppArmor applies an AppArmor profile to a container. KNOWN ISSUE: This writes to /proc/self/attr/current which only affects the calling goroutine, not the actual container process. A correct implementation requires writing to /proc/<pid>/attr/current after the container process has started, which requires an architecture change to defer profile application until after fork/exec.

func ApplySeccomp

func ApplySeccomp(profilePath string) error

ApplySeccomp applies a seccomp profile to the current process (for use before exec).

func DetectBox64

func DetectBox64() bool

DetectBox64 checks if Box64 is available.

func DetectFEXEmu

func DetectFEXEmu() bool

DetectFEXEmu checks if FEX-Emu is available.

func DetectGVisor

func DetectGVisor() bool

DetectGVisor checks if gVisor (runsc) is available.

func DetectSysbox

func DetectSysbox() bool

DetectSysbox checks if sysbox-runc is available.

func DetectWAMR

func DetectWAMR() bool

DetectWAMR checks if WAMR (iwasm) is available.

func DetectWasmEdge

func DetectWasmEdge() bool

DetectWasmEdge checks if WasmEdge is available.

func Logger

func Logger(component string) *slog.Logger

Logger returns a default logger for runner packages.

Types

type CPUStats

type CPUStats struct {
	Usage    uint64
	Throttle uint64
	System   uint64
}

CPUStats holds CPU usage.

type Config

type Config struct {
	ID                string
	Rootfs            string
	Args              []string
	Env               []string
	Cwd               string
	User              string
	Tty               bool
	Interactive       bool
	Privileged        bool
	ReadOnly          bool
	NetworkMode       common.NetworkMode
	Hostname          string
	Labels            map[string]string
	Annotations       map[string]string
	Mounts            []common.Mount
	Ports             []common.Port
	DNS               []string
	DNSSearch         []string
	DNSOptions        []string
	ExtraHosts        []string
	CapAdd            []string
	CapDrop           []string
	SecurityOpt       []string
	Sysctls           map[string]string
	Resources         *Resources
	StopSignal        string
	StopTimeout       int
	Init              bool
	RestartPolicy     common.RestartPolicy
	RestartMaxRetries int
	HealthCheck       *HealthCheckConfig
	Runtime           string
	LogDriver         common.LogDriver
	ImageRef          string
	ImageDigest       string
	ImageLayers       []string // paths to image layer tarballs
	ImageConfig       *ImageOCIConfig
	RootfsReady       string // path to extracted rootfs
	Platform          string // "linux/arm64", "linux/amd64", "wasi/wasm", etc.
}

type ContainerJSON

type ContainerJSON struct {
	ID            string
	Pid           int
	Status        string
	Config        *Config
	RootfsPath    string
	LogPath       string
	Mode          ExecutionMode
	RestartCount  int
	CreatedAt     time.Time
	StartedAt     time.Time
	FinishedAt    time.Time
	ExitCode      int
	GuestArch     string // For cross-arch modes
	IsolationType string // "hardware", "user-space", "none"
}

ContainerJSON holds full container information for inspect.

type ContainerRunner

type ContainerRunner interface {
	// Name returns the execution mode this runner implements.
	Name() ExecutionMode

	// Detect returns true if this runner can work on the current host.
	// Called once at startup to build the registry.
	Detect() bool

	// Capabilities returns what this runner supports.
	Capabilities() RunnerCapabilities

	// Create prepares the container filesystem, config, OCI spec.
	// Returns the container ID. Does NOT start the process.
	Create(ctx context.Context, cfg *Config) (string, error)

	// Start launches the container process. Returns the PID (or 0 for WASM).
	Start(ctx context.Context, id string) (int, error)

	// Stop sends a signal to the container. timeout=0 → SIGKILL.
	Stop(ctx context.Context, id string, timeout time.Duration) error

	// Exec runs a new process inside a running container.
	Exec(ctx context.Context, id string, cfg *ExecConfig) (int, error)

	// Kill sends an arbitrary signal to the container.
	Kill(ctx context.Context, id string, sig syscall.Signal) error

	// Pause suspends the container (cgroup freezer, SIGSTOP, or VM suspend).
	Pause(ctx context.Context, id string) error

	// Resume resumes a paused container.
	Resume(ctx context.Context, id string) error

	// Wait blocks until the container exits and returns the exit code.
	Wait(ctx context.Context, id string) (int, error)

	// Stats returns resource usage (CPU, memory, I/O).
	Stats(ctx context.Context, id string) (*ContainerStats, error)

	// Inspect returns full container metadata.
	Inspect(ctx context.Context, id string) (*ContainerJSON, error)

	// Cleanup removes all resources (rootfs, state, tmp files).
	Cleanup(ctx context.Context, id string) error
}

ContainerRunner is the contract for any execution mode. Implementations must be goroutine-safe and support context cancellation.

type ContainerState

type ContainerState struct {
	ID           string                `json:"id"`
	Pid          int                   `json:"pid"`
	Status       common.ContainerState `json:"status"`
	Created      time.Time             `json:"created"`
	Started      time.Time             `json:"started,omitempty"`
	Finished     time.Time             `json:"finished,omitempty"`
	ExitCode     int                   `json:"exitCode,omitempty"`
	Bundle       string                `json:"bundle"`
	Config       *Config               `json:"config,omitempty"`
	PidPath      string                `json:"pidPath,omitempty"`
	LogPath      string                `json:"logPath,omitempty"`
	Mode         ExecutionMode         `json:"mode"`
	RestartCount int                   `json:"restartCount,omitempty"`
	HealthStatus *common.HealthStatus  `json:"healthStatus,omitempty"`
	ExitChan     chan struct{}         `json:"-"`
	Cmd          *exec.Cmd             `json:"-"`
}

type ContainerStats

type ContainerStats struct {
	CPU     CPUStats
	Memory  MemoryStats
	Network NetworkStats
	PIDs    int
}

ContainerStats holds resource usage for a container.

type ExecConfig

type ExecConfig struct {
	ID           string
	ContainerID  string
	Args         []string
	Env          []string
	WorkingDir   string
	User         string
	Tty          bool
	AttachStdin  bool
	AttachStdout bool
	AttachStderr bool
	Privileged   bool
}

ExecConfig holds configuration for exec into a running container.

type ExecutionMode

type ExecutionMode int

ExecutionMode defines how a container process is run.

const (
	ModeNative     ExecutionMode = iota // 0: Direct host execution
	ModeProot                           // 1: proot-based isolation
	ModeNamespaces                      // 2: Full Linux namespace isolation
	ModeMicroVM                         // 3: Hardware-level isolation via microVM
	ModeGVisor                          // 4: gVisor systrap user-space kernel
	ModeWASM                            // 5: WasmEdge/WAMR/Wasmtime WASI containers
	ModePkDroid                         // 6: pKVM hardware isolation + Microdroid
	ModeSysbox                          // 7: Rootless DinD via sysbox-runc
	ModeQEMUUser                        // 8: QEMU user-mode cross-arch emulation
	ModeChroot                          // 9: Lightweight chroot isolation
	ModeFEX                             // 10: FEX-Emu/Box64 x86 emulation on ARM64
	ModeLegacy32                        // 11: Dual-arch ARMv7/ARM64 containers
)

func AllExecutionModes

func AllExecutionModes() []ExecutionMode

AllExecutionModes returns all supported execution modes.

func ParseExecutionMode

func ParseExecutionMode(s string) (ExecutionMode, bool)

ParseExecutionMode parses a mode name string into an ExecutionMode.

func (ExecutionMode) String

func (m ExecutionMode) String() string

String returns the human-readable name of the execution mode.

type HealthCheckConfig

type HealthCheckConfig struct {
	Test     []string
	Interval time.Duration
	Timeout  time.Duration
	Retries  int
}

type ImageOCIConfig

type ImageOCIConfig struct {
	Entrypoint  []string
	Cmd         []string
	Env         []string
	WorkingDir  string
	User        string
	Volumes     map[string]struct{}
	Labels      map[string]string
	StopSignal  string
	Shell       []string
	HealthCheck *HealthCheckConfig
}

type MemoryStats

type MemoryStats struct {
	Usage    uint64
	MaxUsage uint64
	Limit    uint64
	Cache    uint64
}

MemoryStats holds memory usage.

type NetworkStats

type NetworkStats struct {
	RxBytes   uint64
	TxBytes   uint64
	RxPackets uint64
	TxPackets uint64
}

NetworkStats holds network I/O.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages all available container runners and selects the best one for a given configuration.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new runner registry.

func (*Registry) AllRunners

func (r *Registry) AllRunners() []RunnerInfo

AllRunners returns info about all known modes (available and unavailable).

func (*Registry) Available

func (r *Registry) Available() []RunnerInfo

Available returns all detected runners with their info.

func (*Registry) BestFor

func (r *Registry) BestFor(cfg *Config) ContainerRunner

BestFor selects the optimal runner for the given configuration. Priority chain:

  1. Explicit --runtime flag (cfg.Runtime)
  2. WASM images → ModeWASM
  3. Cross-arch platform → ModeQEMUUser or ModeFEX
  4. Root available → ModeNamespaces or ModeChroot
  5. KVM available → ModeMicroVM
  6. gVisor available → ModeGVisor
  7. pKVM available → ModePkDroid
  8. proot available → ModeProot
  9. Fallback → ModeNative

func (*Registry) Get

func (r *Registry) Get(mode ExecutionMode) ContainerRunner

Get returns the runner for the given mode, or nil if not available.

func (*Registry) Register

func (r *Registry) Register(runner ContainerRunner)

Register adds a runner to the registry if it's available on this host.

type Resources

type Resources struct {
	CPUShares      int64
	Memory         int64
	MemorySwap     int64
	NanoCpus       int64
	CPUPeriod      int64
	CPUQuota       int64
	CpusetCpus     string
	CpusetMems     string
	PidsLimit      int64
	BlkioWeight    uint16
	OomKillDisable bool
	ShmSize        int64
}

type RunnerCapabilities

type RunnerCapabilities struct {
	Arch          []string // Architectures this runner can execute on
	RootRequired  bool     // Needs root/sudo to function
	KVMRequired   bool     // Needs /dev/kvm
	CrossArch     bool     // Can run foreign-arch binaries
	WASM          bool     // Is a WASM runtime
	HWIsolation   bool     // Hardware-enforced isolation
	PauseSupport  bool     // Supports pause/resume
	ExecSupport   bool     // Supports exec into running container
	StatsSupport  bool     // Supports resource stats
	DinDCapable   bool     // Can run Docker inside the container
	MaxContainers int      // 0 = unlimited
	GuestArch     []string // For cross-arch: which guest archs are supported
}

RunnerCapabilities describes what a runner supports.

type RunnerInfo

type RunnerInfo struct {
	Mode         ExecutionMode
	Name         string
	Capabilities RunnerCapabilities
	Available    bool
}

RunnerInfo holds information about a detected runner.

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

Runtime implements the OCI Runtime Specification.

func NewRuntime

func NewRuntime(root string, store *storage.Manager, opts ...RuntimeOption) *Runtime

func (*Runtime) Create

func (rt *Runtime) Create(cfg *Config) (*ContainerState, error)

func (*Runtime) Delete

func (rt *Runtime) Delete(id string, force bool) error

func (*Runtime) Exec

func (rt *Runtime) Exec(id string, args []string, env []string, workingDir, user string) ([]byte, []byte, error)

func (*Runtime) GetLogs

func (rt *Runtime) GetLogs(id string, tail int) (string, error)

func (*Runtime) Kill

func (rt *Runtime) Kill(id string, signal syscall.Signal) error

func (*Runtime) List

func (rt *Runtime) List() ([]*ContainerState, error)

func (*Runtime) Mode

func (rt *Runtime) Mode() ExecutionMode

func (*Runtime) Pause

func (rt *Runtime) Pause(id string) error

func (*Runtime) Processes

func (rt *Runtime) Processes(id string) ([]string, error)

func (*Runtime) Registry

func (rt *Runtime) Registry() *Registry

Registry returns the runner registry, or nil if not set.

func (*Runtime) SaveState added in v0.9.3

func (rt *Runtime) SaveState(state *ContainerState) error

SaveState persists the container state to disk.

func (*Runtime) Start

func (rt *Runtime) Start(id string) error

func (*Runtime) StartHealthcheck

func (rt *Runtime) StartHealthcheck(id string, cmd []string, interval, timeout time.Duration, retries int)

StartHealthcheck begins periodic health checks for a container.

func (*Runtime) State

func (rt *Runtime) State(id string) (*ContainerState, error)

func (*Runtime) Stats

func (rt *Runtime) Stats(id string) (map[string]interface{}, error)

func (*Runtime) Stop

func (rt *Runtime) Stop(id string, timeout int) error

func (*Runtime) Unpause

func (rt *Runtime) Unpause(id string) error

type RuntimeOption

type RuntimeOption func(*Runtime)

RuntimeOption is a functional option for NewRuntime.

func WithDNSAddr

func WithDNSAddr(addr string) RuntimeOption

WithDNSAddr sets the internal DNS server address for container resolv.conf.

func WithRegistry

func WithRegistry(reg *Registry) RuntimeOption

WithRegistry sets the runner registry for the runtime.

Directories

Path Synopsis
runners
chroot
Package chroot implements the lightweight chroot container runner.
Package chroot implements the lightweight chroot container runner.
fex
Package fex implements the FEX-Emu/Box64 container runner for x86 emulation on ARM64.
Package fex implements the FEX-Emu/Box64 container runner for x86 emulation on ARM64.
gvisor
Package gvisor implements the gVisor container runner.
Package gvisor implements the gVisor container runner.
legacy32
Package legacy32 implements the dual-arch ARMv7/ARM64 container runner.
Package legacy32 implements the dual-arch ARMv7/ARM64 container runner.
microvm
Package microvm implements the microVM container runner.
Package microvm implements the microVM container runner.
namespaces
Package namespaces implements the Linux namespaces container runner.
Package namespaces implements the Linux namespaces container runner.
native
Package native implements the native container runner.
Package native implements the native container runner.
pkdroid
Package pkdroid implements the pKVM hardware isolation container runner.
Package pkdroid implements the pKVM hardware isolation container runner.
proot
Package proot implements the proot container runner.
Package proot implements the proot container runner.
qemuuser
Package qemuuser implements the QEMU user-mode cross-arch container runner.
Package qemuuser implements the QEMU user-mode cross-arch container runner.
sysbox
Package sysbox implements the rootless DinD container runner.
Package sysbox implements the rootless DinD container runner.
wasm
Package wasm implements the WASM/WASI container runner.
Package wasm implements the WASM/WASI container runner.

Jump to

Keyboard shortcuts

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