sandbox

package
v2.6.2 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sandbox owns the ephemeral LXC lifecycle: clone template, start, run, destroy.

Target kind 'sandbox' puts the Proxmox TEMPLATE vmid in `host`. Every attempt gets its own linked clone; the container IS the isolation, so no git worktree is needed and bypassPermissions is safe. Host-side pct commands run through the target's (local) executor so mock mode can script the whole lifecycle.

Index

Constants

This section is empty.

Variables

View Source
var PluginHooks func(ref string) ([]byte, error)

PluginHooks returns a plugin sandbox provider's hooks file for a config path "plugin:<id>/<provider>" (internal/plugins); set at startup.

Functions

func Destroy

func Destroy(ctx context.Context, host executor.Executor, vmid string, log *slog.Logger)

Destroy stops and removes a container, best-effort.

func Hash added in v2.6.0

func Hash(data []byte) string

Hash is what a person trusts: the file's sha256.

func IsPluginProvider added in v2.6.0

func IsPluginProvider(p string) bool

IsPluginProvider reports whether a hooks path names a plugin's provider.

func IsRepoURL

func IsRepoURL(repoPath string) bool

IsRepoURL reports whether a project's repo_path must be cloned rather than being a path already baked into the template.

func Provision

func Provision(ctx context.Context, host executor.Executor, templateVMID string, attemptID int64, log *slog.Logger) (string, error)

Provision clones the template, starts it, and waits for it to answer.

Types

type Config added in v2.6.0

type Config struct {
	// Provider is "proxmox" (the default: host holds the template vmid),
	// "docker" or "script".
	Provider string `json:"provider,omitempty"`
	// Docker: Image to run, the Machine (a target name) whose docker CLI to
	// use ("" = this server), an optional DockerHost (-H) and extra run args.
	Image      string   `json:"image,omitempty"`
	Machine    string   `json:"machine,omitempty"`
	DockerHost string   `json:"docker_host,omitempty"`
	RunArgs    []string `json:"run_args,omitempty"`
	// Script: path to a lectern.sandbox.yaml on the machine that runs the
	// hooks. "{repo}" is the project's repo path. Hooks only run while the
	// file matches a hash a person trusted (Trusted, path -> sha256).
	ConfigPath string            `json:"config_path,omitempty"`
	Trusted    map[string]string `json:"trusted,omitempty"`
	// Env is given to every sandbox this target makes.
	Env map[string]string `json:"env,omitempty"`
	// OnFinish is what happens when an attempt ends: "destroy" (default),
	// "suspend" or "keep".
	OnFinish string `json:"on_finish,omitempty"`
}

Config is a sandbox target's sandbox_json.

func ParseConfig added in v2.6.0

func ParseConfig(raw string) Config

ParseConfig reads targets.sandbox_json; empty means Proxmox.

func (Config) JSON added in v2.6.0

func (c Config) JSON() string

JSON renders the config for storage.

func (Config) ResolvePath added in v2.6.0

func (c Config) ResolvePath(repo string) string

ResolvePath fills {repo} in the script config path.

func (Config) Validate added in v2.6.0

func (c Config) Validate() error

Validate checks a config a person is saving.

type CreateRequest added in v2.6.0

type CreateRequest struct {
	AttemptID int64
	Name      string
	Env       map[string]string
}

CreateRequest is what a sandbox is made for.

type Docker added in v2.6.0

type Docker struct {
	Host   executor.Executor
	Cfg    Config
	Remote []string // ssh argv prefix to the machine, for terminals; nil = local
}

Docker runs each sandbox as a container, on this server or on any machine Lectern reaches (its docker CLI is driven through that machine's executor).

func (*Docker) Attach added in v2.6.0

func (d *Docker) Attach(id, inner string) ([]string, error)

func (*Docker) Can added in v2.6.0

func (d *Docker) Can(op string) bool

func (*Docker) Create added in v2.6.0

func (d *Docker) Create(ctx context.Context, req CreateRequest) (string, error)

func (*Docker) Destroy added in v2.6.0

func (d *Docker) Destroy(ctx context.Context, id string) error

func (*Docker) Exec added in v2.6.0

func (d *Docker) Exec(id string) executor.Executor

func (*Docker) Name added in v2.6.0

func (d *Docker) Name() string

func (*Docker) Resume added in v2.6.0

func (d *Docker) Resume(ctx context.Context, id string) error

func (*Docker) Suspend added in v2.6.0

func (d *Docker) Suspend(ctx context.Context, id string) error

type Hooks added in v2.6.0

type Hooks struct {
	Create  string            `yaml:"create"`
	Exec    string            `yaml:"exec"`
	Suspend string            `yaml:"suspend"`
	Resume  string            `yaml:"resume"`
	Destroy string            `yaml:"destroy"`
	Attach  string            `yaml:"attach"`
	Env     map[string]string `yaml:"env"`
}

Hooks is a lectern.sandbox.yaml: shell snippets for each lifecycle step. Every hook sees LECTERN_SANDBOX_ID (except create), LECTERN_ATTEMPT_ID, LECTERN_SANDBOX_NAME and the sandbox env. exec also sees LECTERN_COMMAND and LECTERN_CWD, and must pass stdin through.

func ParseHooks added in v2.6.0

func ParseHooks(data []byte) (Hooks, error)

ParseHooks reads a lectern.sandbox.yaml.

type Provider added in v2.6.0

type Provider interface {
	Name() string
	// Create makes a sandbox, starts it and waits until it runs commands.
	Create(ctx context.Context, req CreateRequest) (string, error)
	// Exec is an executor whose commands run inside the sandbox.
	Exec(id string) executor.Executor
	Suspend(ctx context.Context, id string) error
	Resume(ctx context.Context, id string) error
	Destroy(ctx context.Context, id string) error
	// Can reports whether an optional operation ("suspend", "resume",
	// "attach") is available.
	Can(op string) bool
	// Attach is the argv that runs inner (already a command line) inside the
	// sandbox with a terminal, for the web terminal.
	Attach(id string, inner string) ([]string, error)
}

A Provider makes and drives sandboxes of one kind (docs/sandboxes.md): Proxmox linked clones, Docker containers, or anything a user can script. Every provider's commands run through a host executor, so mock mode and a remote Docker machine work the same way as the control plane itself.

type Proxmox added in v2.6.0

type Proxmox struct {
	Host     executor.Executor
	Template string
	Log      *slog.Logger
}

Proxmox is the original provider: a linked clone of a template LXC.

func (*Proxmox) Attach added in v2.6.0

func (p *Proxmox) Attach(id, inner string) ([]string, error)

func (*Proxmox) Can added in v2.6.0

func (p *Proxmox) Can(op string) bool

func (*Proxmox) Create added in v2.6.0

func (p *Proxmox) Create(ctx context.Context, req CreateRequest) (string, error)

func (*Proxmox) Destroy added in v2.6.0

func (p *Proxmox) Destroy(ctx context.Context, id string) error

func (*Proxmox) Exec added in v2.6.0

func (p *Proxmox) Exec(id string) executor.Executor

func (*Proxmox) Name added in v2.6.0

func (p *Proxmox) Name() string

func (*Proxmox) Resume added in v2.6.0

func (p *Proxmox) Resume(ctx context.Context, id string) error

func (*Proxmox) Suspend added in v2.6.0

func (p *Proxmox) Suspend(ctx context.Context, id string) error

type Script added in v2.6.0

type Script struct {
	Host  executor.Executor
	Hooks Hooks
	Env   map[string]string
	Name_ string
}

Script is the bring-your-own provider: Fly, Modal, Vercel, a VM API, anything with a CLI, wired through the hooks file.

func LoadScript added in v2.6.0

func LoadScript(ctx context.Context, host executor.Executor, cfg Config, repo string) (*Script, error)

LoadScript reads the hooks file through host and refuses it unless its hash is the one a person trusted, so an agent that edits the file cannot get its hooks run on the Lectern server.

func (*Script) Attach added in v2.6.0

func (s *Script) Attach(id, inner string) ([]string, error)

func (*Script) Can added in v2.6.0

func (s *Script) Can(op string) bool

func (*Script) Create added in v2.6.0

func (s *Script) Create(ctx context.Context, req CreateRequest) (string, error)

func (*Script) Destroy added in v2.6.0

func (s *Script) Destroy(ctx context.Context, id string) error

func (*Script) Exec added in v2.6.0

func (s *Script) Exec(id string) executor.Executor

func (*Script) Name added in v2.6.0

func (s *Script) Name() string

func (*Script) Resume added in v2.6.0

func (s *Script) Resume(ctx context.Context, id string) error

func (*Script) Suspend added in v2.6.0

func (s *Script) Suspend(ctx context.Context, id string) error

Jump to

Keyboard shortcuts

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