models

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxCredentialKeys  = 32
	MaxCredentialBytes = 4096
)

MaxCredentialKeys / MaxCredentialBytes bound credential payload size so a malicious request can't blow up daemon memory.

View Source
const (
	RuntimeDocker = "docker" // Docker's standard runc-backed runtime.
	RuntimeGvisor = "gvisor" // gVisor (runsc). User-space kernel for untrusted workloads.
	RuntimeKata   = "kata"   // Reserved: Kata Containers. Not yet implemented; rejected at create time.
)

User-facing runtime identifiers. These are the values the API, SDK, and stored sandbox row carry — chosen to match what an operator searching for "Docker" or "gVisor isolation" would type. The pkg/docker layer translates each one to the underlying OCI runtime binary name (runc / runsc / ...) when shaping the daemon request.

The empty string is reserved for legacy rows that pre-date the runtime field — those resolve to the host default at start time.

View Source
const (
	DefaultCPU      float64 = 1
	DefaultMemoryMB int     = 1024
	DefaultDiskGB   int     = 10
)

DefaultCPU, DefaultMemoryMB, DefaultDiskGB are the values normalizeCreateRequest substitutes when the caller leaves them at zero. Exported so any code path that has to reason about an un-normalized CreateSandboxRequest (placement scoring on the way IN, failover-recreate target selection on the way OUT) uses the same numbers — drift here causes placement to score against ghost capacity that doesn't match the eventual admission reservation.

View Source
const (
	ImageDistributionExternalRegistry = "external_registry"
	ImageDistributionAOCR             = "aocr"
	ImageDistributionLocalOnly        = "local_only"
)
View Source
const (
	FailoverPolicyNone     = "none"
	FailoverPolicyRecreate = "recreate"
)
View Source
const (
	ExposedPortProtocolHTTP = "http"
	ExposedPortProtocolTCP  = "tcp"
	ExposedPortProtocolTLS  = "tls"
)

Exposed port protocols. http is the original behavior (Caddy HTTP reverse proxy); tcp and tls are the caddy-l4 paths added with the L4 work.

View Source
const (
	FacadeDaytona = "daytona"
	FacadeE2B     = "e2b"
)

Facade names used by sandbox_compat_state, snapshot_aliases, and request_idempotency. The string is the only thing persisted, so renaming a facade later would require a one-shot UPDATE.

View Source
const (
	RequestStatePending = "pending"
	RequestStateReady   = "ready"
)

Idempotent-request states for request_idempotency.state. Pending means a write is in flight and holds the row's lock; Ready means the write completed and retries within ReplayUntil should replay TargetID instead of running again.

View Source
const MaxLifecycleDuration = 30 * 24 * time.Hour

MaxLifecycleDuration caps each Lifecycle field. 30 days is generous for any reasonable workload while still rejecting typos like "87600h" that would otherwise sit in the DB pretending to be useful.

View Source
const MaxMountsPerSandbox = 8

MaxMountsPerSandbox caps fan-out so a malicious request can't make sandboxd build an arbitrarily large container spec.

Variables

View Source
var ErrRuntimeNotImplemented = errors.New("runtime not yet implemented on this build")

ErrRuntimeNotImplemented is returned when a runtime is recognized as a valid identifier but the implementation has not been wired up yet. Today only "kata" hits this path. Surfaced through the API as a 4xx so operators get an actionable error instead of a generic 500.

Functions

func NormalizeFailoverPolicy added in v0.2.2

func NormalizeFailoverPolicy(policy string) (string, error)

func NormalizeImageDistributionMode added in v0.2.1

func NormalizeImageDistributionMode(mode string) (string, error)

func ResolveOCIRuntime

func ResolveOCIRuntime(value string) (string, error)

ResolveOCIRuntime maps a user-facing runtime identifier to the OCI runtime binary name to set on Docker's HostConfig.Runtime. Returns the binary name and true on success, or ErrRuntimeNotImplemented if the identifier is valid but the build does not implement it yet (today: kata).

The empty string is treated as "no override" — the caller leaves HostConfig.Runtime unset and Docker uses its compiled-in default. The "docker" identifier maps to "" for the same reason: avoiding an explicit "runc" entry means the daemon is happy even when /etc/docker/daemon.json has no runtimes.runc map entry, which is the common case.

func ValidExposedPortProtocol added in v0.1.4

func ValidExposedPortProtocol(value string) (string, error)

ValidExposedPortProtocol normalizes "" to http (the historical default) and rejects unknown values. Any caller that surfaces user input must run it through this before persistence.

func ValidRuntime

func ValidRuntime(value string) (string, error)

ValidRuntime normalizes and validates a user-facing runtime identifier. Empty input passes through unchanged so the caller can substitute the host default; any other value must be one of the recognized names. The intent here is "fail fast at the API boundary" — by the time a request reaches the runtime layer, we should already know the value is one we can act on.

Types

type CreateSandboxRequest

type CreateSandboxRequest struct {
	Image string `json:"image"`
	// ImageDistributionMode classifies whether Image can be pulled on any
	// worker (external_registry/aocr) or is pinned to the local node
	// (local_only). Empty is resolved by the service from snapshot metadata
	// or by the default image distribution provider.
	ImageDistributionMode string     `json:"image_distribution_mode,omitempty"`
	ImageDigest           string     `json:"image_digest,omitempty"`
	ImageRegistryRef      string     `json:"image_registry_ref,omitempty"`
	ImageVerifiedAt       *time.Time `json:"image_verified_at,omitempty"`
	// CPU is the number of CPU cores to allocate. Fractional values are
	// supported (e.g. 0.5 = half a core, 1.5 = one and a half cores).
	// Translates to Docker's CpuQuota at 100ms periods.
	CPU              float64           `json:"cpu"`
	MemoryMB         int               `json:"memory_mb"`
	DiskGB           int               `json:"disk_gb"`
	Env              map[string]string `json:"env"`
	OSUser           string            `json:"os_user"`
	NetworkBlockAll  bool              `json:"network_block_all"`
	Registry         *RegistryAuth     `json:"registry,omitempty"`
	ContainerCommand []string          `json:"container_command,omitempty"`
	Mounts           []MountSpec       `json:"mounts,omitempty"`
	Lifecycle        *Lifecycle        `json:"lifecycle,omitempty"`
	Failover         *Failover         `json:"failover,omitempty"`
	// Name is an optional human-readable identifier. When set, it must be
	// unique across all sandboxes — the store enforces this with a partial
	// unique index. Empty means no name; the sandbox can only be referenced
	// by ID. The Daytona facade requires names; the native /v1 API and other
	// facades may set or omit it.
	Name string `json:"name,omitempty"`
	// Tags is an optional free-form key/value map associated with the
	// sandbox. Used by facades that expose label-style metadata (Daytona
	// labels, E2B metadata).
	Tags map[string]string `json:"tags,omitempty"`
	// Runtime selects the container runtime for this sandbox. Empty falls back
	// to the host default (SB_CONTAINER_RUNTIME). Allowed values: "docker"
	// (standard runc-backed Docker runtime, default), "gvisor" (runsc-backed
	// userspace kernel — use for untrusted workloads), or "kata" (reserved,
	// not yet implemented).
	Runtime string `json:"runtime,omitempty"`
	// GPUs attaches GPU resources to the sandbox. Nil means no GPU. GPU access
	// is not supported with the gVisor runtime — the API returns an error if
	// both GPUs and runtime="gvisor" are set.
	GPUs *GPURequest `json:"gpus,omitempty"`
	// NetworkBytesInLimit caps lifetime ingress bytes for the sandbox. Zero
	// means unlimited. When the cumulative counter crosses the limit, the
	// reconcile loop installs an ingress DROP rule. The "we already paid for
	// the bytes you see in the meter" caveat applies — host-side ingress is
	// counted after the NIC has accepted the packet.
	NetworkBytesInLimit int64 `json:"network_bytes_in_limit,omitempty"`
	// NetworkBytesOutLimit caps lifetime egress bytes. Zero means unlimited.
	// Crossing the limit installs an egress DROP rule via the same primitive
	// NetworkBlockAll uses.
	NetworkBytesOutLimit int64 `json:"network_bytes_out_limit,omitempty"`
}

func (*CreateSandboxRequest) ApplyImageDistribution added in v0.2.1

func (r *CreateSandboxRequest) ApplyImageDistribution(meta ImageDistributionMetadata)

func (CreateSandboxRequest) ImageDistribution added in v0.2.1

func (r CreateSandboxRequest) ImageDistribution() ImageDistributionMetadata

func (CreateSandboxRequest) ShouldRecreateOnFailover added in v0.2.2

func (r CreateSandboxRequest) ShouldRecreateOnFailover() bool

type CreateSandboxResponse

type CreateSandboxResponse struct {
	Sandbox
	SSHPrivateKey string `json:"ssh_private_key,omitempty"`
}

CreateSandboxResponse is what the API returns from POST /v1/sandboxes. SSHPrivateKey is generated server-side per sandbox and returned exactly once — it is never persisted and never returned again. The corresponding public key is stored on the sandbox record and is the only key authorized to SSH into that sandbox.

type CreateSandboxSnapshotRequest added in v0.1.7

type CreateSandboxSnapshotRequest struct {
	Name string `json:"name"`
}

CreateSandboxSnapshotRequest creates a reusable local image snapshot from an existing sandbox container. Name is the image reference callers can later pass back into CreateSandboxRequest.Image.

type CreateSessionRequest

type CreateSessionRequest struct {
	// Name is the human-friendly session label. Two callers asking for the
	// same Name see the same session (idempotent attach). Default "default".
	Name    string            `json:"name,omitempty"`
	Argv    []string          `json:"argv,omitempty"`
	Command string            `json:"command,omitempty"`
	WorkDir string            `json:"workdir,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
	PTY     bool              `json:"pty,omitempty"`
	Cols    int               `json:"cols,omitempty"`
	Rows    int               `json:"rows,omitempty"`
}

CreateSessionRequest is the body of POST /sessions on toolboxd (and the shape the sandboxd proxy forwards). Either Argv or Command may be supplied; Command is run via `sh -c` for convenience.

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

type ExecRequest

type ExecRequest struct {
	Command        string            `json:"command"`
	WorkDir        string            `json:"workdir,omitempty"`
	Env            map[string]string `json:"env,omitempty"`
	TimeoutSeconds int               `json:"timeout_seconds,omitempty"`
}

type ExecResult

type ExecResult struct {
	Stdout     string `json:"stdout"`
	Stderr     string `json:"stderr"`
	ExitCode   int    `json:"exit_code"`
	DurationMS int64  `json:"duration_ms"`
}

type ExposePortRequest added in v0.1.4

type ExposePortRequest struct {
	Protocol string `json:"protocol,omitempty"`
}

ExposePortRequest is the optional JSON body for POST /v1/sandboxes/{id}/ports/{port}. Empty body or empty Protocol falls back to "http" — the historical default — so old SDK callers keep working unchanged.

type ExposePortResponse added in v0.1.6

type ExposePortResponse struct {
	Protocol  string `json:"protocol"`
	PublicURL string `json:"public_url"`
	Host      string `json:"host,omitempty"`
	HostPort  int    `json:"host_port,omitempty"`
}

ExposePortResponse is the JSON body returned by POST /v1/sandboxes/{id}/ports/{port}. Protocol is the canonical value the daemon picked ("http", "tcp", or "tls"), PublicURL is the dialable URL for the exposure, and Host/HostPort are populated only on the raw-TCP path so SDKs can hand them to native protocol clients without parsing tcp://host:port out of PublicURL.

type ExposedPort

type ExposedPort struct {
	SandboxID string `json:"sandbox_id"`
	Port      int    `json:"port"`
	// Protocol is one of "http" (default — Caddy HTTP reverse proxy), "tcp"
	// (caddy-l4 listener bound to HostPort, raw TCP forward to the container),
	// or "tls" (caddy-l4 SNI route on the shared TLS listener). Pre-migration
	// rows carry "http" via the column default.
	Protocol string `json:"protocol"`
	// HostPort is the parent-host TCP listener allocated for protocol="tcp"
	// from the configured pool (default [22000, 23000]). Zero for http/tls
	// modes, which don't reserve a per-exposure host port.
	HostPort  int       `json:"host_port,omitempty"`
	PublicURL string    `json:"public_url"`
	CreatedAt time.Time `json:"created_at"`
}

type Failover added in v0.2.2

type Failover struct {
	Policy string `json:"policy,omitempty"`
}

Failover controls what the cluster should do if the sandbox's owner node is declared dead. Empty or omitted means "none": orphan the placement and return 410 Gone. "recreate" opts the sandbox into best-effort recreation from its replicated create spec on another worker.

func (Failover) NormalizedPolicy added in v0.2.2

func (f Failover) NormalizedPolicy() string

func (Failover) ShouldRecreate added in v0.2.2

func (f Failover) ShouldRecreate() bool

func (Failover) Validate added in v0.2.2

func (f Failover) Validate() error

type GPURequest added in v0.1.3

type GPURequest struct {
	// Vendor is required. Allowed values: "nvidia", "amd", "apple".
	Vendor GPUVendor `json:"vendor"`
	// Count is the number of GPUs to allocate. Use -1 to request all GPUs on
	// the host. Zero is treated as 1 (default). Ignored for AMD (all AMD GPUs
	// on the host are exposed via /dev/kfd and /dev/dri).
	Count int `json:"count,omitempty"`
	// DeviceIDs pins the sandbox to specific GPU device indices or UUIDs.
	// For NVIDIA: GPU indices ("0", "1") or UUIDs ("GPU-abc123...").
	// For AMD and Apple: ignored.
	DeviceIDs []string `json:"device_ids,omitempty"`
}

GPURequest describes the GPU resources to attach to a sandbox. The parent CreateSandboxRequest.GPUs field is a pointer, so omitting it entirely means no GPU — this struct only appears when the caller explicitly opts in.

func (*GPURequest) Validate added in v0.1.3

func (g *GPURequest) Validate() error

Validate checks GPURequest fields for consistency.

type GPUVendor added in v0.1.3

type GPUVendor string

GPUVendor identifies the GPU hardware vendor for sandbox GPU allocation.

const (
	// GPUVendorNVIDIA selects NVIDIA GPUs via nvidia-container-runtime.
	// Requires nvidia-container-toolkit installed on the host.
	GPUVendorNVIDIA GPUVendor = "nvidia"
	// GPUVendorAMD selects AMD GPUs via ROCm device bind-mounts (/dev/kfd,
	// /dev/dri). Requires ROCm drivers on the host.
	GPUVendorAMD GPUVendor = "amd"
	// GPUVendorApple selects Apple Silicon GPU via Docker Desktop's
	// experimental Metal support. Only functional on macOS with Docker Desktop;
	// Linux hosts will receive a Docker daemon error at container creation.
	GPUVendorApple GPUVendor = "apple"
)

type HealthStatus

type HealthStatus struct {
	Status          string `json:"status"`
	Sandboxes       int    `json:"sandboxes"`
	Docker          string `json:"docker"`
	Caddy           string `json:"caddy"`
	SSHGateway      string `json:"ssh_gateway"`
	ClusterTopology string `json:"cluster_topology,omitempty"`
	ClusterNodes    int    `json:"cluster_nodes,omitempty"`
	Version         string `json:"version"`
}

type IdempotentRequestRecord added in v0.1.7

type IdempotentRequestRecord struct {
	Scope       string
	Fingerprint string
	TargetID    string
	State       string
	LockedUntil time.Time
	ReplayUntil time.Time
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

IdempotentRequestRecord is the row shape for request_idempotency. Scope is a facade-defined namespace string (e.g. "e2b.create") so the same fingerprint hash can be reused across facades without collision. The generic store helpers stay facade-agnostic — only the scope string says which caller owns the row.

type ImageDistributionMetadata added in v0.2.1

type ImageDistributionMetadata struct {
	Mode        string     `json:"mode,omitempty"`
	Digest      string     `json:"digest,omitempty"`
	RegistryRef string     `json:"registry_ref,omitempty"`
	VerifiedAt  *time.Time `json:"verified_at,omitempty"`
}

ImageDistributionMetadata describes whether an image can be materialized on an arbitrary worker. It is deliberately metadata only: registries, AOCR, and cache services remain pluggable deployment choices outside the core daemon.

func (ImageDistributionMetadata) IsZero added in v0.2.1

func (m ImageDistributionMetadata) IsZero() bool

type Lifecycle

type Lifecycle struct {
	StopIfIdleFor    time.Duration `json:"stop_if_idle_for,omitempty"`
	DestroyIfIdleFor time.Duration `json:"destroy_if_idle_for,omitempty"`
	StopAtAge        time.Duration `json:"stop_at_age,omitempty"`
	DestroyAtAge     time.Duration `json:"destroy_at_age,omitempty"`
}

Lifecycle declares automatic stop/destroy timers for a sandbox. Each field is a duration; zero means "disabled" for that axis. Idle triggers measure time since LastActiveAt (i.e. since the last toolbox/exec/SSH activity). Age triggers measure time since CreatedAt — they are absolute deadlines that do not reset on Stop+Start, so a "destroy at 24h" sandbox stays destroyable even if the user restarts it minutes before the deadline.

Multiple fields can be set; whichever timer fires first wins. Destroy supersedes Stop for the same trigger axis. The lifecycle sweep runs every minute, so deadlines are honored to roughly that resolution.

func (Lifecycle) IsZero

func (l Lifecycle) IsZero() bool

IsZero reports whether all four timers are disabled. Useful for skipping Lifecycle inspection in the sweep when there's nothing to evaluate.

func (Lifecycle) Validate

func (l Lifecycle) Validate() error

Validate enforces the invariants we rely on at sweep time:

  • no negative durations (zero means disabled, negative is meaningless),
  • each field <= MaxLifecycleDuration,
  • if both stop and destroy of the same trigger are set, destroy must not fire before stop. Without this we could surprise a user who set "stop at 2h, destroy at 1h" by skipping the stop entirely.

type MountSpec

type MountSpec struct {
	Type        MountType         `json:"type"`
	Target      string            `json:"target"`
	Source      string            `json:"source"`
	Options     map[string]string `json:"options,omitempty"`
	Credentials map[string]string `json:"credentials,omitempty"`
	ReadOnly    bool              `json:"read_only,omitempty"`
}

MountSpec describes a single external-storage mount the user wants to be available inside their sandbox. Credentials are encrypted at rest in the daemon's database, materialized only on the host as the FUSE process needs them, and never returned by any read API.

func (*MountSpec) Redact

func (m *MountSpec) Redact() MountSpecRedacted

Redact strips credentials, returning the user-safe view.

func (*MountSpec) Validate

func (m *MountSpec) Validate(toolboxMountPath string) error

Validate checks the spec against the daemon's mount policy. toolboxMountPath is the path the toolbox binary is bind-mounted to inside the container; we refuse to let the user shadow it.

type MountSpecFile

type MountSpecFile struct {
	Mounts []MountSpec `json:"mounts"`
}

MountSpecFile is the JSON envelope used to (de)serialize the encrypted blob of a sandbox's mount specs in the daemon's database. Kept as a struct rather than a bare slice so future fields (version, key id) can be added without a migration.

type MountSpecRedacted

type MountSpecRedacted struct {
	Type           MountType         `json:"type"`
	Target         string            `json:"target"`
	Source         string            `json:"source"`
	Options        map[string]string `json:"options,omitempty"`
	ReadOnly       bool              `json:"read_only,omitempty"`
	HasCredentials bool              `json:"has_credentials"`
}

MountSpecRedacted is the read-only view returned by the API. It mirrors MountSpec but strips credentials.

func RedactMounts

func RedactMounts(mounts []MountSpec) []MountSpecRedacted

RedactMounts returns the read-only API view for a slice of mounts.

type MountType

type MountType string

MountType identifies the storage backend the user wants mounted inside their container. The daemon runs the mount tool on the host (in a per-sandbox directory) and bind-mounts that directory into the container, so credentials never enter the container and the user's image needs no mount tooling.

const (
	MountTypeS3     MountType = "s3"
	MountTypeNFS    MountType = "nfs"
	MountTypeSSHFS  MountType = "sshfs"
	MountTypeRclone MountType = "rclone"
)

type NetworkUsage added in v0.1.7

type NetworkUsage struct {
	SandboxID       string     `json:"sandbox_id"`
	BytesIn         int64      `json:"bytes_in"`
	BytesOut        int64      `json:"bytes_out"`
	BytesInLimit    int64      `json:"bytes_in_limit"`
	BytesOutLimit   int64      `json:"bytes_out_limit"`
	QuotaExceeded   bool       `json:"quota_exceeded"`
	QuotaExceededAt *time.Time `json:"quota_exceeded_at,omitempty"`
	// LastSampledAt is omitted until the netstats poller has produced at
	// least one sample. Pointer + omitempty so we don't serialize the zero
	// time as "0001-01-01T00:00:00Z" before the first tick.
	LastSampledAt *time.Time `json:"last_sampled_at,omitempty"`
}

NetworkUsage is the response shape for GET /v1/sandboxes/{id}/network/usage. BytesInLimit / BytesOutLimit zero means unlimited.

type RegistryAuth

type RegistryAuth struct {
	Server   string `json:"server"`
	Username string `json:"username"`
	Password string `json:"password"`
}

type ResizeSandboxRequest

type ResizeSandboxRequest struct {
	CPU      float64 `json:"cpu"`
	MemoryMB int     `json:"memory_mb"`
	DiskGB   int     `json:"disk_gb"`
}

type Sandbox

type Sandbox struct {
	ID               string            `json:"id"`
	Image            string            `json:"image"`
	Status           SandboxStatus     `json:"status"`
	PublicURL        string            `json:"public_url"`
	ContainerID      string            `json:"container_id,omitempty"`
	ContainerIP      string            `json:"container_ip,omitempty"`
	CPU              float64           `json:"cpu"`
	MemoryMB         int               `json:"memory_mb"`
	DiskGB           int               `json:"disk_gb"`
	OSUser           string            `json:"os_user"`
	Env              map[string]string `json:"env,omitempty"`
	NetworkBlockAll  bool              `json:"network_block_all"`
	ToolboxEnabled   bool              `json:"toolbox_enabled"`
	ToolboxToken     string            `json:"-"`
	SSHPublicKey     string            `json:"ssh_public_key,omitempty"`
	ExposedPorts     []ExposedPort     `json:"exposed_ports,omitempty"`
	CreatedAt        time.Time         `json:"created_at"`
	UpdatedAt        time.Time         `json:"updated_at"`
	LastActiveAt     time.Time         `json:"last_active_at"`
	LastError        string            `json:"last_error,omitempty"`
	ContainerCommand []string          `json:"container_command,omitempty"`
	Lifecycle        Lifecycle         `json:"lifecycle"`
	Failover         *Failover         `json:"failover,omitempty"`
	// Name is the optional unique identifier set at create time. Empty when
	// the sandbox was created without one (the common path on /v1 today).
	Name string `json:"name,omitempty"`
	// Tags is the optional key/value bag set at create time. Facades use it
	// for label-style metadata (Daytona labels, E2B metadata) but the field
	// is facade-agnostic — anything that wants attribute-tagged sandboxes
	// can write here.
	Tags map[string]string `json:"tags,omitempty"`
	// Runtime is the container runtime this sandbox uses (one of "docker",
	// "gvisor", or "kata"). Pre-migration rows carry "" and resolve to the
	// host default at start time; new sandboxes always store the resolved
	// value so the choice cannot drift across host restarts.
	Runtime string `json:"runtime"`
	// GPUs is the GPU configuration this sandbox was created with. Nil means
	// no GPU was requested.
	GPUs *GPURequest `json:"gpus,omitempty"`
	// RegistryAuthSealed is the AES-GCM-encrypted JSON of the original
	// RegistryAuth supplied at create time, or nil/empty when the sandbox
	// pulled from a public registry. Persisted so cluster failover can hand
	// the credentials back to the new owner's docker pull. Never serialized
	// over the API — it is internal store ↔ service plumbing.
	RegistryAuthSealed []byte `json:"-"`
	// NetworkBytesIn / NetworkBytesOut are cumulative byte counters
	// maintained by the netstats poller. They survive container restarts —
	// a new veth resets in-memory baseline math but the persisted total is
	// preserved.
	NetworkBytesIn  int64 `json:"network_bytes_in"`
	NetworkBytesOut int64 `json:"network_bytes_out"`
	// NetworkBytesInLimit / NetworkBytesOutLimit are the caps the sandbox was
	// created or patched with. Zero = unlimited.
	NetworkBytesInLimit  int64 `json:"network_bytes_in_limit"`
	NetworkBytesOutLimit int64 `json:"network_bytes_out_limit"`
	// NetworkQuotaExceeded reflects whether either lifetime byte counter has
	// crossed its limit. The reconcile loop installs DROP rules when this is
	// true; clearing requires raising the limit (or zeroing it for unlimited).
	NetworkQuotaExceeded bool `json:"network_quota_exceeded"`
	// NetworkQuotaExceededAt is the wall-clock time the limit was first
	// observed crossed. Nil while under quota.
	NetworkQuotaExceededAt *time.Time `json:"network_quota_exceeded_at,omitempty"`
}

type SandboxCompatState added in v0.1.7

type SandboxCompatState struct {
	SandboxID string
	Facade    string
	StateJSON string
	CreatedAt time.Time
	UpdatedAt time.Time
}

SandboxCompatState carries facade-private state that has no native meaning on its own — opaque wire-shape sugar like Daytona's `target` or E2B's `template_id`. The store treats StateJSON as a byte string; facades own the schema inside it.

type SandboxRuntimeState

type SandboxRuntimeState struct {
	SandboxID   string
	ContainerID string
	ContainerIP string
	Status      SandboxStatus
}

SandboxRuntimeState is the runtime view of a sandbox returned by the container runtime layer (Docker today, gVisor/native runsc tomorrow). It carries only what the service needs to reconcile and route — anything else belongs on models.Sandbox or stays in the runtime implementation.

type SandboxSnapshot added in v0.1.7

type SandboxSnapshot struct {
	Name            string    `json:"name"`
	Image           string    `json:"image"`
	ImageID         string    `json:"image_id,omitempty"`
	SourceSandboxID string    `json:"source_sandbox_id"`
	CreatedAt       time.Time `json:"created_at"`
	// Image distribution metadata is the snapshot-level placement contract.
	// Local-only snapshots may be started only on the node whose Docker image
	// store contains Image; external_registry/aocr snapshots may be placed on
	// any worker that can pull RegistryRef/Image.
	ImageDistributionMode string     `json:"image_distribution_mode,omitempty"`
	ImageDigest           string     `json:"image_digest,omitempty"`
	ImageRegistryRef      string     `json:"image_registry_ref,omitempty"`
	ImageVerifiedAt       *time.Time `json:"image_verified_at,omitempty"`

	// Entrypoint is the optional command override the caller wants the
	// runtime to use when starting a sandbox from this snapshot.
	Entrypoint []string `json:"entrypoint,omitempty"`
	// RegionID echoes the region the caller requested when creating the
	// snapshot. The facade persists this verbatim for read-back; region
	// routing itself is not yet wired through the daemon.
	RegionID string `json:"region_id,omitempty"`
	// CPU / MemoryMB / DiskGB / GPU mirror the resource hints the caller
	// supplied on create — surfaced back to clients that poll the snapshot
	// after creation.
	CPU      float64 `json:"cpu,omitempty"`
	MemoryMB int     `json:"memory_mb,omitempty"`
	DiskGB   int     `json:"disk_gb,omitempty"`
	GPU      float64 `json:"gpu,omitempty"`
}

SandboxSnapshot is the persisted metadata for a committed sandbox image. Image is the reusable image reference; ImageID is the content-addressed Docker image ID returned by the runtime after the commit succeeds.

Two creation paths populate this row:

  1. Snapshot-of-a-running-sandbox (legacy) — SourceSandboxID is set, resource fields stay zero, the image is committed by the runtime.
  2. Snapshot-from-image (Daytona facade) — SourceSandboxID is empty, resource fields and Entrypoint reflect the caller's create payload, and Image is either the caller-supplied imageName or a freshly built tag from a buildInfo Dockerfile.

func (*SandboxSnapshot) ApplyImageDistribution added in v0.2.1

func (s *SandboxSnapshot) ApplyImageDistribution(meta ImageDistributionMetadata)

func (SandboxSnapshot) ImageDistribution added in v0.2.1

func (s SandboxSnapshot) ImageDistribution() ImageDistributionMetadata

type SandboxStatus

type SandboxStatus string
const (
	SandboxStatusCreating  SandboxStatus = "creating"
	SandboxStatusStarted   SandboxStatus = "started"
	SandboxStatusStopped   SandboxStatus = "stopped"
	SandboxStatusDestroyed SandboxStatus = "destroyed"
	SandboxStatusError     SandboxStatus = "error"
)

Sandbox lifecycle states.

SandboxStatusDestroyed marks a sandbox whose container is gone — either because the user called DELETE /sandboxes/{id}, or because the container died out-of-band and the event monitor noticed. The status exists as a transient marker only: the API-driven destroy path deletes the row in the same call, and the reconcile loop deletes any row whose container has gone missing on its next pass. Destroyed rows are not retained — keeping them around would also keep their host_port reservations in exposed_ports, slowly exhausting the L4 TCP allocator pool over the daemon's lifetime.

type Session

type Session struct {
	ID         string        `json:"id"`
	Name       string        `json:"name"`
	Argv       []string      `json:"argv"`
	WorkDir    string        `json:"workdir,omitempty"`
	PTY        bool          `json:"pty"`
	Status     SessionStatus `json:"status"`
	ExitCode   int           `json:"exit_code"`
	ExitSignal string        `json:"exit_signal,omitempty"`
	CreatedAt  time.Time     `json:"created_at"`
	StartedAt  time.Time     `json:"started_at"`
	ExitedAt   time.Time     `json:"exited_at,omitempty"`
	Recording  bool          `json:"recording"`
	Bytes      int64         `json:"bytes"`    // total stdout+stderr bytes produced
	Attached   int           `json:"attached"` // current number of attached clients
}

Session is the metadata view of a session — never includes its output.

type SessionList

type SessionList struct {
	Sessions []Session `json:"sessions"`
}

SessionList is the GET /sessions response shape.

type SessionResizeRequest

type SessionResizeRequest struct {
	Cols int `json:"cols"`
	Rows int `json:"rows"`
}

SessionResizeRequest is the POST /sessions/{id}/resize body.

type SessionSignalRequest

type SessionSignalRequest struct {
	Signal string `json:"signal"`
}

SessionSignalRequest is the POST /sessions/{id}/signal body. Signal is one of INT, TERM, KILL, HUP, QUIT (or the SIG*-prefixed forms).

type SessionStatus

type SessionStatus string

SessionStatus is the lifecycle stage of a long-running command session inside a sandbox container.

const (
	SessionStatusRunning SessionStatus = "running"
	SessionStatusExited  SessionStatus = "exited"
	SessionStatusKilled  SessionStatus = "killed"
	SessionStatusFailed  SessionStatus = "failed" // could not start
)

type SnapshotAlias added in v0.1.7

type SnapshotAlias struct {
	Alias        string
	SnapshotName string
	Facade       string
	ExtraNames   []string
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

SnapshotAlias maps a facade-shaped alternate identifier (e.g. E2B's base64-encoded `snapshot_*` token) onto a native sandbox_snapshots.name. ExtraNames carries additional facade-visible names that point at the same native snapshot.

type UpdateLifecycleRequest

type UpdateLifecycleRequest struct {
	Lifecycle
}

UpdateLifecycleRequest is the body for PUT /v1/sandboxes/{id}/lifecycle. Full-replacement semantics: send all four fields. To clear a field, set it to zero. To preserve a field, send its current value (read it via GET first if the caller doesn't already have it).

type UpdateNetworkLimitsRequest added in v0.1.7

type UpdateNetworkLimitsRequest struct {
	NetworkBytesInLimit  *int64 `json:"network_bytes_in_limit,omitempty"`
	NetworkBytesOutLimit *int64 `json:"network_bytes_out_limit,omitempty"`
}

UpdateNetworkLimitsRequest is the body for PATCH /v1/sandboxes/{id}/network/limits. Each field is a pointer so the handler can distinguish "leave alone" (nil) from "set to unlimited" (pointer to zero). Negative values are rejected at the service layer.

Jump to

Keyboard shortcuts

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