engine

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound     = errors.New("sandbox not found")
	ErrNotRunning   = errors.New("sandbox is not running")
	ErrLimitReached = errors.New("maximum sandbox limit reached")
)

Functions

This section is empty.

Types

type Engine

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

Engine orchestrates sandbox lifecycle.

func NewEngine

func NewEngine(rt runtime.Runtime, st store.Store, cfg config.SandboxConfig, s3Cfg config.S3Config, logger *slog.Logger) *Engine

NewEngine creates a new Engine.

func (*Engine) CreateSandbox

func (e *Engine) CreateSandbox(ctx context.Context, cfg runtime.SandboxConfig) (*Sandbox, error)

CreateSandbox creates and starts a new sandbox.

func (*Engine) DeleteSnapshot

func (e *Engine) DeleteSnapshot(ctx context.Context, snapshotID string) error

DeleteSnapshot removes a snapshot.

func (*Engine) DestroySandbox

func (e *Engine) DestroySandbox(ctx context.Context, id string) error

DestroySandbox stops and removes a sandbox.

func (*Engine) Exec

func (e *Engine) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (*runtime.ExecResult, error)

Exec runs a command in a sandbox.

func (*Engine) ExecStream

func (e *Engine) ExecStream(ctx context.Context, id string, opts runtime.ExecOpts) (runtime.ExecStream, error)

ExecStream runs a streaming command in a sandbox.

func (*Engine) GetSandbox

func (e *Engine) GetSandbox(id string) (*Sandbox, error)

GetSandbox returns a sandbox by ID.

func (*Engine) ListDir

func (e *Engine) ListDir(ctx context.Context, id string, path string) ([]runtime.FileInfo, error)

ListDir lists a directory in a sandbox.

func (*Engine) ListSandboxes

func (e *Engine) ListSandboxes() []*Sandbox

ListSandboxes returns all tracked sandboxes.

func (*Engine) ListSnapshots

func (e *Engine) ListSnapshots(ctx context.Context, sandboxID string) ([]runtime.SnapshotInfo, error)

ListSnapshots returns all snapshots for a sandbox.

func (*Engine) MkDir

func (e *Engine) MkDir(ctx context.Context, id string, path string) error

MkDir creates a directory in a sandbox.

func (*Engine) ReadFile

func (e *Engine) ReadFile(ctx context.Context, id string, path string) ([]byte, error)

ReadFile reads a file from a sandbox.

func (*Engine) RemoveFile

func (e *Engine) RemoveFile(ctx context.Context, id string, path string) error

RemoveFile removes a file from a sandbox.

func (*Engine) RestoreSnapshot

func (e *Engine) RestoreSnapshot(ctx context.Context, snapshotID string) (*Sandbox, error)

RestoreSnapshot restores a sandbox from a snapshot.

func (*Engine) Shutdown

func (e *Engine) Shutdown(_ context.Context)

Shutdown gracefully stops all sandboxes. Uses a detached context so shutdown is not cancelled by the caller's context.

func (*Engine) Snapshot

func (e *Engine) Snapshot(ctx context.Context, id string, name string) (*runtime.SnapshotInfo, error)

Snapshot creates a snapshot of a sandbox.

func (*Engine) Stats

func (e *Engine) Stats(ctx context.Context, id string) (*runtime.SandboxStats, error)

Stats returns stats for a sandbox.

func (*Engine) StopSandbox

func (e *Engine) StopSandbox(ctx context.Context, id string) error

StopSandbox stops a sandbox without removing it.

func (*Engine) WriteFile

func (e *Engine) WriteFile(ctx context.Context, id string, path string, content []byte) error

WriteFile writes a file to a sandbox.

type Sandbox

type Sandbox struct {
	ID    string `json:"id"`
	Image string `json:"image"`

	Config    runtime.SandboxConfig `json:"-"`
	CreatedAt time.Time             `json:"created_at"`
	ExpiresAt time.Time             `json:"expires_at,omitempty"`
	Ports     []runtime.PortMapping `json:"ports,omitempty"`
	// contains filtered or unexported fields
}

Sandbox represents a managed sandbox instance.

func (*Sandbox) GetStatus

func (s *Sandbox) GetStatus() runtime.SandboxStatus

GetStatus returns the sandbox status (thread-safe).

func (*Sandbox) IsExpired

func (s *Sandbox) IsExpired() bool

IsExpired returns true if the sandbox has exceeded its timeout.

func (*Sandbox) MarshalJSON

func (s *Sandbox) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling to include the status field.

func (*Sandbox) SetStatus

func (s *Sandbox) SetStatus(status runtime.SandboxStatus)

SetStatus updates the sandbox status (thread-safe).

type WarmPool

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

WarmPool pre-creates containers so sandbox creation is near-instant.

func NewWarmPool

func NewWarmPool(rt runtime.Runtime, size int, cfg runtime.SandboxConfig, logger *slog.Logger) *WarmPool

NewWarmPool creates a warm pool that maintains `size` pre-created containers.

func (*WarmPool) Acquire

func (wp *WarmPool) Acquire() string

Acquire gets a pre-warmed container ID from the pool. Returns empty string if pool is empty (caller should create normally).

func (*WarmPool) Return

func (wp *WarmPool) Return(ctx context.Context, id string)

Return puts an unused container ID back to the pool or removes it.

func (*WarmPool) Size

func (wp *WarmPool) Size() int

Size returns the current number of warm containers.

func (*WarmPool) Stop

func (wp *WarmPool) Stop(ctx context.Context)

Stop drains and destroys all warm containers.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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