sandbox

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 24 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 creates and manages sandboxes with a hosted provider. A sandbox is a machine to the rest of conch: once it runs, conch installs itself there and reaches it over ssh like any other. This package only talks to the provider; it knows nothing of conch's servers.

Index

Constants

View Source
const DefaultBoatURL = "https://boat.dev/api/v1"

DefaultBoatURL is boat.dev's API.

View Source
const DefaultDaytonaAnalyticsURL = "https://analytics.app.daytona.io"

DefaultDaytonaAnalyticsURL is where Daytona reports what has been used. It is a separate host from the API, and its numbers settle hours behind what is running now.

View Source
const DefaultDaytonaURL = "https://app.daytona.io/api"

DefaultDaytonaURL is Daytona's API.

View Source
const DefaultDevinURL = "https://api.devin.ai"

DefaultDevinURL is Devin's API.

View Source
const DefaultE2BURL = "https://api.e2b.app"

DefaultE2BURL is E2B's platform API.

View Source
const DefaultTensorlakeSSH = "sandbox.tensorlake.ai"

DefaultTensorlakeSSH is the gateway every sandbox is reached through.

View Source
const DefaultTensorlakeURL = "https://api.tensorlake.ai"

DefaultTensorlakeURL is Tensorlake's API.

View Source
const Label = "conch"

Label marks the sandboxes conch created, so List leaves others alone.

View Source
const ProviderFormat = 2

ProviderFormat is the newest provider file this conch reads. A file that needs what format 1 lacked says format = 2, which a conch from before formats calls an unknown key and refuses: refusing is right, since it would otherwise send {public_key} as those very letters.

View Source
const RegistryRepo = "Amitgb14/conch-sandbox-providers"

RegistryRepo is where provider files are published to.

Variables

View Source
var (
	// ErrNotConfigured is returned when a provider has no credentials.
	ErrNotConfigured = errors.New("sandbox provider not configured")
	// ErrNotFound is returned for a sandbox the provider doesn't have.
	ErrNotFound = errors.New("no such sandbox")
)
View Source
var Names = func() []string {
	good, _ := CustomProviders()
	return append(append([]string(nil), builtin...), good...)
}

Names lists the providers conch knows: its own, then the ones described by a file in ProvidersDir that loads. It reads the folder each time, so a provider saved a moment ago is there. Tests replace it.

View Source
var ProviderFileGuide string

ProviderFileGuide is the format, as the agent drafting a file is told it.

View Source
var PublicKey func(ctx context.Context) (string, error)

PublicKey is the public key a sandbox is made with when a provider file puts {public_key} in its create body. internal/remote sets it (the person's own key, else conch's), since that is where keys are found.

Functions

func Builtin added in v0.2.0

func Builtin(name string) bool

Builtin reports whether name is a provider conch has built in, rather than one described by a file.

func CheckName added in v0.2.0

func CheckName(name string) error

CheckName says whether name can be a provider's. A name becomes a path — providers/NAME.toml, its draft's folder — and arrives from the registry's index, a command line and an agent's draft, so it is checked before any path is made of it: "../x" would otherwise write, or remove, a file outside providers/.

func CustomProviders added in v0.2.0

func CustomProviders() (good []string, bad map[string]string)

CustomProviders lists the provider files that load, by name. One that does not — unreadable, wrong, or a built-in's name — is left out and said in bad, so the list never offers a provider that would fail.

func EditedSinceInstall added in v0.2.0

func EditedSinceInstall(name string, in Installed) (bool, error)

EditedSinceInstall says whether name's file is no longer as it came from the registry. A file that is gone is not edited: there is nothing to keep.

func EnvFrom

func EnvFrom(names []string) (map[string]string, error)

EnvFrom reads the named variables from this environment, to pass into a new sandbox. A name that isn't set is refused, rather than passed in empty for an agent to trip on.

func FetchProviderFile added in v0.2.0

func FetchProviderFile(ctx context.Context, e RegistryEntry) ([]byte, error)

FetchProviderFile downloads e's file and checks it is the one the index lists, byte for byte.

func FileHosts added in v0.2.0

func FileHosts(f *ProviderFile) (api, ssh string)

FileHosts are the hosts a provider file sends the key and ssh to.

func FileKey added in v0.2.0

func FileKey(f *ProviderFile) (keyEnv, authHeader, authValue string)

FileKey is how a provider file sends a key: the variable it is read from, and the header and value it goes in (empty for the defaults).

func ForgetInstalled added in v0.2.0

func ForgetInstalled(name string) error

ForgetInstalled drops name from the record, when its file is removed.

func IsCustom added in v0.2.0

func IsCustom(name string) bool

IsCustom says whether name is a provider described by a file.

func Known

func Known(name string) bool

Known reports whether name is a provider conch knows.

func Offered added in v0.2.0

func Offered() []string

Offered lists the providers a sandbox is made with from a menu: Names without the ones conch knows but does not offer.

func Pick added in v0.2.0

func Pick(v any, path string) any

Pick reads a dotted path out of a JSON value: "a.b", "items.0.id".

func ProviderFilePath added in v0.2.0

func ProviderFilePath(name string) string

ProviderFilePath is where the file for name is kept.

func ProviderLabel

func ProviderLabel(name string) string

ProviderLabel is a provider's name for people to read.

func ProvidersDir added in v0.2.0

func ProvidersDir() string

ProvidersDir is where provider files are kept.

func ReadInstalled added in v0.2.0

func ReadInstalled() (map[string]Installed, error)

ReadInstalled is every provider installed from the registry. A missing file is none.

func RegistryURL added in v0.2.0

func RegistryURL() string

RegistryURL is the registry conch reads.

Types

type APIError

type APIError struct {
	Status     int
	Message    string
	RetryAfter time.Duration
	// contains filtered or unexported fields
}

APIError is a request Daytona refused.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Is

func (e *APIError) Is(target error) bool

Is makes a 404 match ErrNotFound.

type Access

type Access struct {
	// User is who to log in as. With a provider whose gateway takes the
	// API token as the username it is a secret and is kept out of
	// messages; PlainUser says it is an ordinary account name instead,
	// which must not be hidden — "user" would be struck out of every
	// sentence that happened to contain it.
	User      string
	PlainUser bool
	Host      string
	Port      int // 0 is ssh's default
	Expires   time.Time
}

Access is how to reach a sandbox over ssh, until Expires.

func (Access) Target

func (a Access) Target() string

Target is the ssh destination for Access.

type AccountKeyed added in v0.2.0

type AccountKeyed interface {
	AccountKey() bool
}

AccountKeyed is a provider whose gateway lets in the ssh keys registered with the person's account there, which conch cannot register with an API key: the transport offers the key it would have authorized, and the provider's Note says to register it.

type Boat

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

Boat is the provider.

func NewBoat

func NewBoat(cfg config.ProviderCfg) *Boat

NewBoat returns a boat.dev provider for cfg.

func (*Boat) AuthorizeKey

func (b *Boat) AuthorizeKey(ctx context.Context, id, publicKey string) error

AuthorizeKey lets a public key in. Boat takes the key itself rather than handing out a secret, so conch's own key opens the sandbox and the private half never leaves this computer.

func (*Boat) Check

func (b *Boat) Check() error

func (*Boat) Create

func (b *Boat) Create(ctx context.Context, spec Spec) (Sandbox, error)

func (*Boat) Delete

func (b *Boat) Delete(ctx context.Context, id string) error

Delete throws the sandbox and its snapshots away. Boat wants the id repeated in a header before it will, which conch does rather than asking twice: it has already asked.

func (*Boat) ForgetSnapshot

func (b *Boat) ForgetSnapshot(ctx context.Context, name string) error

ForgetSnapshot releases a named snapshot. Boat keeps ten of them, so this is how you make room for another.

func (*Boat) Get

func (b *Boat) Get(ctx context.Context, id string) (Sandbox, error)

func (*Boat) Life

func (b *Boat) Life() time.Duration

Life is how long a new sandbox is given, so the dialog that makes one can say it: boat's clock, not conch's.

func (*Boat) List

func (b *Boat) List(ctx context.Context) ([]Sandbox, error)

List returns the account's sandboxes. Boat has no labels, so conch cannot tell the ones it made from the ones you made yourself; the machines it knows about are the ones in its own catalog.

func (*Boat) Name

func (b *Boat) Name() string

func (*Boat) PreviewURL

func (b *Boat) PreviewURL(ctx context.Context, id string, port int, _ time.Duration) (string, error)

PreviewURL exposes a port and returns its link. Boat's link is sticky — the same port answers at the same address next time — and carries its own token unless it was made public, so expires is not something it takes.

func (*Boat) SSHAccess

func (b *Boat) SSHAccess(ctx context.Context, id string) (Access, error)

SSHAccess is where to ssh, once a key has been authorized: boat's sandboxes have an sshd of their own, so there is no token in this — AuthorizeKey is what makes the way in.

A sandbox that has just come up may have no address for a moment — boat reports it once the machine has one — so this waits for it rather than failing a create that was going to work.

func (*Boat) SizeNames

func (b *Boat) SizeNames() []string

SizeNames says boat's machines are sized by name, so nothing offers a number of vCPUs for one.

func (*Boat) Snapshot

func (b *Boat) Snapshot(ctx context.Context, id, name string) error

Snapshot keeps the sandbox under a name, to deploy others from. Boat takes a fresh capture of a running sandbox first, which takes minutes; the name is ready when it says it is.

func (*Boat) Snapshots

func (b *Boat) Snapshots(ctx context.Context) ([]Snap, error)

Snapshots lists the named ones, which are the ones you can deploy from.

func (*Boat) Start

func (b *Boat) Start(ctx context.Context, id string) (Sandbox, error)

Start brings a stopped sandbox back. Boat has no start: a stopped one is resumed onto a new machine, keeping its id and its disk, which is why its address must be read again afterwards.

func (*Boat) Stop

func (b *Boat) Stop(ctx context.Context, id string) error

Stop archives the sandbox: boat snapshots it first and refuses to stop one whose snapshot is failing, so nothing is lost. That refusal is passed on rather than forced.

func (*Boat) Usage

func (b *Boat) Usage(ctx context.Context, id string, from, to time.Time) (Usage, error)

Usage is what boat says the sandbox has cost: machine time while it was running, which is all boat charges for — a stopped sandbox keeps its disk for nothing.

type BoatError

type BoatError struct {
	Status  int
	Message string
	// Code is boat's own name for the refusal, e.g. billing_required.
	Code string
	// contains filtered or unexported fields
}

BoatError is what boat.dev's API answered with.

func (*BoatError) Error

func (e *BoatError) Error() string

func (*BoatError) Is

func (e *BoatError) Is(target error) bool

Is makes a 404 match ErrNotFound.

type Call added in v0.2.0

type Call struct {
	Call string         `toml:"call"`
	Body map[string]any `toml:"body"`
}

Call is one request: "METHOD /path", the path's {id} filled in, and a body whose string values may be placeholders.

type CommandAccess added in v0.1.7

type CommandAccess interface {
	SSHCommand(id string) ([]string, error)
}

CommandAccess is a provider whose sandboxes are reached through a program of its own that wraps ssh — Devin's `devin ssh` — rather than at an address conch can ssh to itself. ssh's options and the command to run go after what it returns.

type CreateCall added in v0.2.0

type CreateCall struct {
	Call
	ID string `toml:"id"`
}

CreateCall makes a sandbox; ID is where its id is in the reply.

type Custom added in v0.2.0

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

Custom is a provider described by a file.

func NewCustom added in v0.2.0

func NewCustom(f *ProviderFile, cfg config.ProviderCfg) *Custom

NewCustom returns the provider f describes, with its key from cfg or the environment.

func (*Custom) AccountKey added in v0.2.0

func (c *Custom) AccountKey() bool

AccountKey says ssh is opened by a key registered with the account.

func (*Custom) AuthorizeKey added in v0.2.0

func (c *Custom) AuthorizeKey(ctx context.Context, id, publicKey string) error

AuthorizeKey hands a public key over, when the file says how.

func (*Custom) AuthorizesKey added in v0.2.0

func (c *Custom) AuthorizesKey() bool

AuthorizesKey says whether conch hands its key over through the API.

func (*Custom) Check added in v0.2.0

func (c *Custom) Check() error

func (*Custom) Count added in v0.2.0

func (c *Custom) Count(ctx context.Context) (all, mine int, err error)

Count is how many sandboxes the account has, conch's or not: the check that the key and the list call work, without making anything.

func (*Custom) Create added in v0.2.0

func (c *Custom) Create(ctx context.Context, spec Spec) (Sandbox, error)

func (*Custom) Delete added in v0.2.0

func (c *Custom) Delete(ctx context.Context, id string) error

func (*Custom) File added in v0.2.0

func (c *Custom) File() *ProviderFile

File is the description it was made from.

func (*Custom) Get added in v0.2.0

func (c *Custom) Get(ctx context.Context, id string) (Sandbox, error)

func (*Custom) List added in v0.2.0

func (c *Custom) List(ctx context.Context) ([]Sandbox, error)

func (*Custom) Name added in v0.2.0

func (c *Custom) Name() string

func (*Custom) Note added in v0.2.0

func (c *Custom) Note() string

Note is the file's own, after saying where the provider came from.

func (*Custom) SSHAccess added in v0.2.0

func (c *Custom) SSHAccess(ctx context.Context, id string) (Access, error)

func (*Custom) Start added in v0.2.0

func (c *Custom) Start(ctx context.Context, id string) (Sandbox, error)

func (*Custom) Stop added in v0.2.0

func (c *Custom) Stop(ctx context.Context, id string) error

type Daytona

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

Daytona manages sandboxes through Daytona's REST API.

func NewDaytona

func NewDaytona(cfg config.ProviderCfg) *Daytona

NewDaytona returns a Daytona provider for cfg, reading the key and any unset endpoint or region from the environment.

func (*Daytona) Check

func (d *Daytona) Check() error

func (*Daytona) Create

func (d *Daytona) Create(ctx context.Context, spec Spec) (Sandbox, error)

func (*Daytona) Delete

func (d *Daytona) Delete(ctx context.Context, id string) error

func (*Daytona) ForgetSnapshot

func (d *Daytona) ForgetSnapshot(ctx context.Context, name string) error

ForgetSnapshot removes a kept sandbox. Daytona keeps charging for one nobody uses, so this is the other half of making them.

func (*Daytona) Get

func (d *Daytona) Get(ctx context.Context, id string) (Sandbox, error)

func (*Daytona) List

func (d *Daytona) List(ctx context.Context) ([]Sandbox, error)

func (*Daytona) Name

func (d *Daytona) Name() string

func (*Daytona) PreviewURL

func (d *Daytona) PreviewURL(ctx context.Context, id string, port int, expires time.Duration) (string, error)

PreviewURL is a signed link to a port inside the sandbox. The plain preview link needs a header a browser will not send, so conch asks for the signed kind, which carries its token in the host name and expires on its own. Daytona signs one for at most a day.

func (*Daytona) SSHAccess

func (d *Daytona) SSHAccess(ctx context.Context, id string) (Access, error)

func (*Daytona) Snapshot

func (d *Daytona) Snapshot(ctx context.Context, id, name string) error

Snapshot keeps the sandbox as it stands, to make others from. Daytona takes a cold snapshot of a container sandbox, which wants it stopped first: that is the caller's to arrange, and its refusal comes back as it is rather than being guessed at.

func (*Daytona) Snapshots

func (d *Daytona) Snapshots(ctx context.Context) ([]Snap, error)

Snapshots lists what has been kept. Daytona pages them; conch asks for the newest first and stops at a page it has seen.

func (*Daytona) Start

func (d *Daytona) Start(ctx context.Context, id string) (Sandbox, error)

func (*Daytona) Stop

func (d *Daytona) Stop(ctx context.Context, id string) error

func (*Daytona) Usage

func (d *Daytona) Usage(ctx context.Context, id string, from, to time.Time) (Usage, error)

Usage is what Daytona says the sandbox has cost. Its analytics are a different host, keyed by the organization, which conch learns from the sandbox itself rather than asking anyone to configure it. Nothing to report is not an error: Daytona's figures settle well behind the hour they are about.

type Devin added in v0.1.7

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

Devin is the provider.

func NewDevin added in v0.1.7

func NewDevin(cfg config.ProviderCfg) *Devin

NewDevin returns a Devin Cloud provider for cfg.

func (*Devin) Check added in v0.1.7

func (d *Devin) Check() error

func (*Devin) Create added in v0.1.7

func (d *Devin) Create(ctx context.Context, spec Spec) (Sandbox, error)

func (*Devin) Delete added in v0.1.7

func (d *Devin) Delete(ctx context.Context, id string) error

Delete ends the session. Devin keeps an ended session's record, which conch no longer lists.

func (*Devin) Get added in v0.1.7

func (d *Devin) Get(ctx context.Context, id string) (Sandbox, error)

func (*Devin) List added in v0.1.7

func (d *Devin) List(ctx context.Context) ([]Sandbox, error)

List returns the sessions conch made: the ones tagged with its label. Sessions that have ended are left out, as a deleted sandbox is.

func (*Devin) Name added in v0.1.7

func (d *Devin) Name() string

func (*Devin) Note added in v0.1.7

func (d *Devin) Note() string

Note says what is unlike other providers' machines: Devin works in the session and bills for it, the way in is the devin CLI, and an idle session is put to sleep.

func (*Devin) PlaceHint added in v0.1.7

func (d *Devin) PlaceHint() string

PlaceHint says what goes where the snapshot does: Devin runs a session on a platform the organization offers, or on an outpost pool.

func (*Devin) SSHAccess added in v0.1.7

func (d *Devin) SSHAccess(ctx context.Context, id string) (Access, error)

SSHAccess is where the VM is, for completeness: plain ssh there asks for approval in a browser, so conch goes in with SSHCommand instead.

func (*Devin) SSHCommand added in v0.1.7

func (d *Devin) SSHCommand(id string) ([]string, error)

SSHCommand is `devin ssh ID`: the devin CLI approves the connection with its own login, which an API key cannot.

func (*Devin) Start added in v0.1.7

func (d *Devin) Start(ctx context.Context, id string) (Sandbox, error)

Start wakes a sleeping session. Devin has no call for that: an archived session is unarchived, and a message wakes it.

func (*Devin) Stop added in v0.1.7

func (d *Devin) Stop(ctx context.Context, id string) error

Stop puts the session to sleep, keeping its VM. The API's way to do that is to archive it; Start unarchives it again.

type DevinError added in v0.1.7

type DevinError struct {
	Status  int
	Message string
	// contains filtered or unexported fields
}

DevinError is what Devin's API answered with.

func (*DevinError) Error added in v0.1.7

func (e *DevinError) Error() string

func (*DevinError) Is added in v0.1.7

func (e *DevinError) Is(target error) bool

Is makes a 404 match ErrNotFound.

type E2B

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

E2B is the provider.

func NewE2B

func NewE2B(cfg config.ProviderCfg) *E2B

NewE2B returns an E2B provider for cfg, reading the key and any unset endpoint from the environment.

func (*E2B) Check

func (e *E2B) Check() error

func (*E2B) Create

func (e *E2B) Create(ctx context.Context, spec Spec) (Sandbox, error)

func (*E2B) Delete

func (e *E2B) Delete(ctx context.Context, id string) error

Delete ends the sandbox for good. One E2B has already forgotten counts as deleted, so cleaning up after a delete made elsewhere works.

func (*E2B) Get

func (e *E2B) Get(ctx context.Context, id string) (Sandbox, error)

func (*E2B) List

func (e *E2B) List(ctx context.Context) ([]Sandbox, error)

List returns the sandboxes conch made, running or paused. E2B filters by the metadata conch sets, so somebody else's sandboxes in the same account are left alone.

func (*E2B) Name

func (e *E2B) Name() string

func (*E2B) Refresh

func (e *E2B) Refresh(ctx context.Context, id string, d time.Duration) error

Refresh pushes the sandbox's end back, so one that is being worked in isn't ended under the agent. E2B's timeout is from now, not added to what is left, so this sets the whole of it each time.

func (*E2B) SSHAccess

func (e *E2B) SSHAccess(ctx context.Context, id string) (Access, error)

SSHAccess says what E2B cannot do. conch reaches its sandboxes through envd instead; Reach says so, and the transport asks for envdAccess.

func (*E2B) Start

func (e *E2B) Start(ctx context.Context, id string) (Sandbox, error)

Start resumes a paused sandbox. One already running is left alone, so starting twice is not an error.

func (*E2B) Stop

func (e *E2B) Stop(ctx context.Context, id string) error

Stop pauses the sandbox: its filesystem and memory are kept, so what ran there is still running when it comes back.

type E2BError

type E2BError struct {
	Status  int
	Message string
	// contains filtered or unexported fields
}

E2BError is what E2B's API answered with.

func (*E2BError) Error

func (e *E2BError) Error() string

func (*E2BError) Is

func (e *E2BError) Is(target error) bool

Is makes a 404 match ErrNotFound.

type FailedError

type FailedError struct {
	ID     string
	State  State
	Reason string
}

FailedError is a sandbox that ended up in an error state while conch waited for it to start.

func (*FailedError) Error

func (e *FailedError) Error() string

type GetCall added in v0.2.0

type GetCall struct {
	Call
	Item     string `toml:"item"`
	State    string `toml:"state"`
	Name     string `toml:"name"`
	Reason   string `toml:"reason"`
	CPU      string `toml:"cpu"`
	MemoryMB string `toml:"memory_mb"`
	DiskMB   string `toml:"disk_mb"`
	Created  string `toml:"created"`
}

GetCall looks at one; each field is a path into the reply — into Item, where the reply wraps the sandbox ({"server": {...}}). A list's items are read with the same paths, unwrapped.

type Index added in v0.2.0

type Index struct {
	Format    int             `json:"format"`
	Providers []RegistryEntry `json:"providers"`
}

Index is the registry's list.

func FetchIndex added in v0.2.0

func FetchIndex(ctx context.Context) (*Index, error)

FetchIndex reads the registry's list.

func (*Index) Find added in v0.2.0

func (ix *Index) Find(name string) (RegistryEntry, bool)

Find is the entry for name.

func (*Index) ForHost added in v0.2.0

func (ix *Index) ForHost(host string) (RegistryEntry, bool)

ForHost is the entry whose API is at host, or whose docs are, for a URL somebody is about to adapt: no need to adapt what is already here.

func (*Index) Search added in v0.2.0

func (ix *Index) Search(term string) []RegistryEntry

Search is the entries whose name, label or API host holds term, every one for an empty term.

type Installed added in v0.2.0

type Installed struct {
	SHA256     string `json:"sha256"`
	APIHost    string `json:"api_host"`
	SSHHost    string `json:"ssh_host"`
	KeyEnv     string `json:"key_env,omitempty"`
	AuthHeader string `json:"auth_header,omitempty"`
	AuthValue  string `json:"auth_value,omitempty"`
	Installed  string `json:"installed"`
}

Installed is what was installed from the registry: the file's hash as it came, the hosts it named then, and which of the person's variables it read the key from and how it sent it. A record from before KeyEnv was kept has it empty, which says nothing — not that the file named none (a file must) — so an update asks about it once.

func (Installed) SameKey added in v0.2.0

func (in Installed) SameKey(f *ProviderFile) bool

SameKey says whether f sends the key as in was recorded sending it; false for a record that never said.

type KeyAuthorizer

type KeyAuthorizer interface {
	AuthorizeKey(ctx context.Context, id, publicKey string) error
}

KeyAuthorizer is a provider whose sandboxes are reached with a key of your own rather than a secret it hands out: conch authorizes its public key through the API and the private half never leaves this computer.

type Lifetime

type Lifetime interface {
	// Life is what a new sandbox gets, with this provider's settings.
	Life() time.Duration
}

Lifetime is a provider whose sandboxes are given a length of life when they are made rather than being stopped when nobody uses them, so it is worth saying how long before one is created.

type ListCall added in v0.2.0

type ListCall struct {
	Call
	Items       string `toml:"items"`
	ID          string `toml:"id"`
	Next        string `toml:"next"`
	CursorParam string `toml:"cursor_param"`
	Mine        string `toml:"mine"`
}

ListCall lists the account's sandboxes. Items is where the list is in the reply, and each item is read as Get reads its reply, with ID where the item's id is. Next is where the next page's cursor is, sent back as CursorParam. Mine is the start of the name conch gives every sandbox it makes, which is how its own are told from the account's others.

type Mapping added in v0.2.0

type Mapping struct {
	Does  string `json:"does"`
	Call  string `json:"call"`
	Reads string `json:"reads,omitempty"`
}

Mapping is one line of what conch will do, for a person to check.

type Metered

type Metered interface {
	// Usage is what the sandbox has cost between from and to. Known is
	// false when the provider has nothing to say yet — its billing may
	// lag hours behind — which is not an error.
	Usage(ctx context.Context, id string, from, to time.Time) (Usage, error)
}

Metered is a provider that can say what a sandbox has actually cost, rather than leaving conch to work it out from prices somebody typed.

type NamedSizes

type NamedSizes interface {
	// SizeNames lists the sizes, smallest first.
	SizeNames() []string
}

NamedSizes is a provider whose machines come in named sizes rather than a number of vCPUs, GiB of memory and GiB of disk. The name goes where a snapshot does, and asking for numbers is refused.

type Noted added in v0.1.7

type Noted interface {
	Note() string
}

Noted is a provider with something to say before a sandbox is made with it: a cost or a limit a person would not expect of a machine.

type Placed added in v0.1.7

type Placed interface {
	// PlaceHint says what the snapshot field takes, for a placeholder.
	PlaceHint() string
}

Placed is a provider whose machines are neither sized nor made from a snapshot but placed: on a platform, or on a pool of machines of your own. That place's name goes where the snapshot does, and numbers are refused.

type Previewer

type Previewer interface {
	// PreviewURL is a link to port inside the sandbox that a browser can
	// open on its own, good for about the time asked for. Whatever
	// credential it needs is in the link.
	PreviewURL(ctx context.Context, id string, port int, expires time.Duration) (string, error)
}

Previewer is a provider that can give a link to a port inside a sandbox, so a dev server an agent started can be looked at. Not every provider can, so it is asked for separately.

type Provider

type Provider interface {
	// Name is the provider, e.g. "daytona".
	Name() string
	// Check says whether the provider can be used: ErrNotConfigured when
	// it has no credentials.
	Check() error
	Create(ctx context.Context, spec Spec) (Sandbox, error)
	Get(ctx context.Context, id string) (Sandbox, error)
	// List returns the sandboxes conch created.
	List(ctx context.Context) ([]Sandbox, error)
	Start(ctx context.Context, id string) (Sandbox, error)
	Stop(ctx context.Context, id string) error
	Delete(ctx context.Context, id string) error
	// SSHAccess returns fresh credentials to reach a started sandbox.
	SSHAccess(ctx context.Context, id string) (Access, error)
}

Provider creates and manages sandboxes. Create and Start return once the sandbox is started, or the context ends.

func Open

func Open(name string, cfg config.SandboxCfg) (Provider, error)

Open returns the named provider, set up from cfg.

type ProviderFile added in v0.2.0

type ProviderFile struct {
	// Format is 1 when left out.
	Format int    `toml:"format"`
	Name   string `toml:"name"`
	Label  string `toml:"label"`
	// API is the base every call's path is put after.
	API    string `toml:"api"`
	KeyEnv string `toml:"key_env"`
	// AuthHeader and AuthValue send the key: "Authorization" and
	// "Bearer {key}" when left out.
	AuthHeader string `toml:"auth_header"`
	AuthValue  string `toml:"auth_value"`
	// Docs is where it was adapted from; AdaptedBy and Adapted who wrote
	// it and when. Only shown.
	Docs      string `toml:"docs"`
	AdaptedBy string `toml:"adapted_by"`
	Adapted   string `toml:"adapted"`
	// Note is said before a sandbox is made with it.
	Note string `toml:"note"`

	Create CreateCall        `toml:"create"`
	Get    GetCall           `toml:"get"`
	List   ListCall          `toml:"list"`
	Start  Call              `toml:"start"`
	Stop   Call              `toml:"stop"`
	Delete Call              `toml:"delete"`
	States map[string]string `toml:"states"`
	SSH    SSHWay            `toml:"ssh"`
}

ProviderFile is the shape of a provider file.

func InstallProviderFile added in v0.2.0

func InstallProviderFile(name string, data []byte) (*ProviderFile, error)

InstallProviderFile keeps data as provider name, installed from the registry. It is checked first: a file this conch cannot run is refused rather than saved and skipped.

func ParseProviderFile added in v0.2.0

func ParseProviderFile(name string, data []byte) (*ProviderFile, []string, error)

ParseProviderFile checks data as a provider file named name, without keeping it anywhere.

func ReadProviderFile added in v0.2.0

func ReadProviderFile(path string) (*ProviderFile, []string, error)

ReadProviderFile reads and checks a provider file, returning what is wrong with it — everything, not the first thing, since the person or the agent fixing it wants the list.

func (*ProviderFile) Describe added in v0.2.0

func (f *ProviderFile) Describe() []Mapping

Describe says in plain lines which call conch makes for what, and what it reads back: the review a person does before saving the file.

func (*ProviderFile) Problems added in v0.2.0

func (f *ProviderFile) Problems() []string

Problems lists what is wrong with the file, or nothing.

type RegistryCheck added in v0.2.0

type RegistryCheck struct {
	Date      string `json:"date"`
	Conch     string `json:"conch"`
	Sandboxes int    `json:"sandboxes"`
}

RegistryCheck is the last time somebody's key listed sandboxes with a provider's file.

type RegistryEntry added in v0.2.0

type RegistryEntry struct {
	Name      string         `json:"name"`
	Label     string         `json:"label"`
	API       string         `json:"api"`
	APIHost   string         `json:"api_host"`
	SSHHost   string         `json:"ssh_host"`
	KeyEnv    string         `json:"key_env"`
	Format    int            `json:"format"`
	Note      string         `json:"note,omitempty"`
	File      string         `json:"file"`
	SHA256    string         `json:"sha256"`
	AdaptedBy string         `json:"adapted_by"`
	Adapted   string         `json:"adapted"`
	Docs      string         `json:"docs"`
	Conch     string         `json:"conch"`
	Checked   *RegistryCheck `json:"checked"`
}

RegistryEntry is one provider in the index.

type SSHWay added in v0.2.0

type SSHWay struct {
	Host string `toml:"host"`
	User string `toml:"user"`
	Port int    `toml:"port"`
	Key  string `toml:"key"`
	// Authorize lets a public key in ({public_key} in its body).
	Authorize Call `toml:"authorize"`
	// Access is asked before each connection when the way in is a
	// credential handed out per connection; Host and User may then read
	// its reply as {reply.PATH}.
	Access Call `toml:"access"`
}

SSHWay is how ssh gets in. Key says whose key opens it: "account", a key registered with the person's account there; "authorize", one conch hands over through Authorize; "none", a credential in User from Access.

type Sandbox

type Sandbox struct {
	ID      string
	Name    string
	State   State
	Reason  string // why it is in an error state, when the provider says
	Target  string // region
	CPU     int    // vCPUs
	Memory  int    // GiB
	Disk    int    // GiB
	Labels  map[string]string
	Created time.Time
}

Sandbox is a provider's sandbox.

type Snap

type Snap struct {
	Name    string
	State   string // the provider's own word: active, inactive, building…
	Size    string // vCPU, memory and disk, when the provider says
	Created time.Time
}

Snap is a kept sandbox, as far as conch shows it.

type Snapshotter

type Snapshotter interface {
	// Snapshot keeps the sandbox under name. What the provider needs of
	// the sandbox first — stopped, usually — is its own business to
	// refuse.
	Snapshot(ctx context.Context, id, name string) error
	// Snapshots lists what has been kept, newest first.
	Snapshots(ctx context.Context) ([]Snap, error)
	// ForgetSnapshot removes one.
	ForgetSnapshot(ctx context.Context, name string) error
}

Snapshotter is a provider that can keep a sandbox as it stands and make new ones from it: a checkout, its dependencies and an agent's login, set up once and started again in a minute.

type Spec

type Spec struct {
	Name     string
	Snapshot string
	CPU      int // vCPUs
	Memory   int // GiB
	Disk     int // GiB
	Env      map[string]string
	Labels   map[string]string
	// AutoStop is the minutes without activity before the provider stops
	// the sandbox; 0 never does.
	AutoStop int
}

Spec is what to create. Zero values leave the provider's defaults.

type State

type State string

State is a sandbox's state as its provider reports it.

const (
	StateCreating    State = "creating"
	StateStarting    State = "starting"
	StateStarted     State = "started"
	StateStopping    State = "stopping"
	StateStopped     State = "stopped"
	StateArchived    State = "archived"
	StateError       State = "error"
	StateBuildFailed State = "build_failed"
	StateDestroying  State = "destroying"
	StateDestroyed   State = "destroyed"
)

The states conch acts on; a provider may report others (archiving, resizing…), which pass through as they are.

func (State) Going

func (s State) Going() bool

Going reports whether the sandbox is on its way out, or already gone: nothing brings it back, so conch treats it as no longer there rather than waiting for a state that never settles.

func (State) Moving

func (s State) Moving() bool

Moving reports whether the sandbox is on its way to another state, so asking again shortly will find it settled.

type Tensorlake added in v0.2.0

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

Tensorlake is the provider.

func NewTensorlake added in v0.2.0

func NewTensorlake(cfg config.ProviderCfg) *Tensorlake

NewTensorlake returns a Tensorlake provider for cfg, reading the key and any unset endpoint from the environment.

func (*Tensorlake) AccountKey added in v0.2.0

func (t *Tensorlake) AccountKey() bool

AccountKey says the gateway takes a key registered with the account, so the transport offers the one it would otherwise have authorized.

func (*Tensorlake) Check added in v0.2.0

func (t *Tensorlake) Check() error

func (*Tensorlake) Create added in v0.2.0

func (t *Tensorlake) Create(ctx context.Context, spec Spec) (Sandbox, error)

func (*Tensorlake) Delete added in v0.2.0

func (t *Tensorlake) Delete(ctx context.Context, id string) error

Delete terminates the sandbox. Tensorlake answers success for one that had already ended, so only one it has never heard of is ErrNotFound.

func (*Tensorlake) Get added in v0.2.0

func (t *Tensorlake) Get(ctx context.Context, id string) (Sandbox, error)

func (*Tensorlake) List added in v0.2.0

func (t *Tensorlake) List(ctx context.Context) ([]Sandbox, error)

List returns the sandboxes conch made: the ones whose name it gave.

func (*Tensorlake) Name added in v0.2.0

func (t *Tensorlake) Name() string

func (*Tensorlake) Note added in v0.2.0

func (t *Tensorlake) Note() string

Note says what has to be done once before conch can get in.

func (*Tensorlake) SSHAccess added in v0.2.0

func (t *Tensorlake) SSHAccess(ctx context.Context, id string) (Access, error)

SSHAccess is the gateway, with the sandbox's id as the user: not a secret, since the key registered with the account is what lets one in.

func (*Tensorlake) Start added in v0.2.0

func (t *Tensorlake) Start(ctx context.Context, id string) (Sandbox, error)

Start resumes a suspended sandbox, keeping its disk and its memory.

func (*Tensorlake) Stop added in v0.2.0

func (t *Tensorlake) Stop(ctx context.Context, id string) error

Stop suspends the sandbox: Tensorlake keeps it as it stands, to resume.

type TensorlakeError added in v0.2.0

type TensorlakeError struct {
	Status  int
	Message string
	// contains filtered or unexported fields
}

TensorlakeError is what Tensorlake's API answered with.

func (*TensorlakeError) Error added in v0.2.0

func (e *TensorlakeError) Error() string

type Usage

type Usage struct {
	Cost     float64
	Known    bool
	From, To time.Time
	Periods  []UsagePeriod // newest last, as the provider gives them
}

Usage is what a provider says a sandbox has cost, and the periods it was billed in: a provider charges by what the sandbox was doing, so the periods say where the money went — running, or only keeping its disk.

type UsagePeriod

type UsagePeriod struct {
	From, To time.Time
	CPU      int // vCPUs held; 0 while it is stopped
	MemGiB   int
	DiskGiB  int
	Cost     float64
}

UsagePeriod is one stretch a sandbox was billed for.

func (UsagePeriod) Running

func (p UsagePeriod) Running() bool

Running reports whether the sandbox was up for this period, rather than stopped and keeping its disk.

Jump to

Keyboard shortcuts

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