Skip to content
nc9Public

About

Container and sandbox provider registry and SDK: providers, container types, capabilities and prices, one interface (shared by Longshore and Turntable)

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

berth

A registry and SDK for container and sandbox providers. It does for compute what pi-ai does for LLMs: one list of providers, their container types and their prices, plus one interface to create and drive a sandbox on any of them.

  • Catalog: providers (name, logo, website, description), container types (vCPU, memory, disk, GPU, OS, arch, regions, isolation), capabilities (snapshots, pause and resume, egress controls, lifetime limits) and dated, sourced prices per unit of container time.
  • SDK: one Provider interface (create, exec detached, logs by offset, files, describe, destroy; optional pause, resume and snapshot), with one adapter package per provider.
  • Conformance: one test suite every adapter must pass.

Policy stays with the consumer. Trust tiers, ownership rules, egress mapping and ceilings belong to the products that use berth (Longshore, Turntable). berth reports facts and carries out requests.

Install

bun add @nc9/berth

Zero runtime dependencies. Memory is in MiB everywhere.

Use

import { catalog } from "@nc9/berth";

// All providers (name, website, docs, regions, status, verifiedAt).
catalog.getProviders();

// Filter container types.
const types = catalog.find({
  os: "linux",
  gpuType: "h100",
  minMemoryMiB: 16384,
  minIsolation: "microvm",
  egress: "allowlist",
  status: "ga",
});

// Estimate cost. Range types need vcpu / memoryMiB; active-cpu billing needs cpuSeconds.
const { usd, breakdown, skipped, verifiedAt } = catalog.estimateCost(
  types[0]!,
  {
    seconds: 3600,
    vcpu: 2,
    memoryMiB: 4096,
    region: "us-east",
  },
);

estimateCost prices only time-based dimensions (vcpu, memory, gpu, and disk when diskGiBHours is given). Rates it did not use are listed in skipped, so usd is never silently partial.

Auth methods

Each provider lists how to authenticate in meta.auth: one or more methods (api_key, token_pair, iam_keys, iam_role, ...), exactly one marked default. A method has fields with a stable name, the env variable exactly as the vendor docs name it (omitted when they name none), secret, required and a description. Non-secret fields (API URL, region, project id) may carry an example or default; secret fields never do. envVars is derived from the default method's fields. A method not confirmed in the vendor docs is status: "unverified" with the reason in notes.

Consumers store the config and check it with field presence only, never secret values:

import { validateAuthConfig } from "@nc9/berth";

validateAuthConfig("modal", "token-pair", { "token-id": "present" });
// { missing: ["token-secret"], unknown: [], inlineSecrets: [], ok: false }

Add a custom provider

createCatalog validates the data and throws listing every error.

import { builtInProviders, createCatalog, type Provider } from "@nc9/berth";

const acme: Provider = {
  meta: { id: "acme" /* name, website, docs, pricingUrl, regions, ... */ },
  types: [
    { id: "small", provider: "acme" /* vcpu, memoryMiB, os, arch, ... */ },
  ],
};
const mine = createCatalog([...builtInProviders, acme]);

Pick up newer prices without upgrading

The catalog is also built as public JSON (bun scripts/build-catalog.ts writes dist/catalog.json and dist/catalog.schema.json). mergeCatalog overlays a fetched copy on the built-in data:

import { builtInProviders, createCatalog, mergeCatalog } from "@nc9/berth";

const remote = await (await fetch(url)).json();
const mine = createCatalog(mergeCatalog(builtInProviders, remote));
  • A remote provider wins only when its meta.verifiedAt is newer.
  • Providers the built-in data does not know are added.
  • A malformed remote is ignored with a warning (pass { warn } to capture it); an invalid provider inside it is skipped.
  • Each remote provider is checked against the published JSON Schema and the validators. The remote source must still be trusted: a newer meta.verifiedAt replaces the whole built-in provider, rates included.

bun run catalog:check validates the built JSON against the schema and the validators and exits non-zero on any error.

Logos

Each provider's logo.files points at committed brand images (packages/berth/assets/logos/<id>/<icon|logo>-<light|dark|opaque>.<svg|png>) fetched from context.dev by bun scripts/fetch-logos.ts (manual, needs CONTEXT_DEV_API_KEY, not run in CI). SVGs are sanitized before commit (sanitizeSvg); manifest.json records the domain, retrieval time and source URL of each file, or missing: true with a reason (opaque is context.dev's has_opaque_background variant, used for both themes; providers with no usable image are missing, and aws needs a rerun with an API key to fetch its logo). Entries vendored by hand (docker from simple-icons, CC0-1.0; daytona from its brand page) carry source, licence, licenceUrl and version in the manifest, and fetch-logos.ts keeps them.

Logos are trademarks of their owners, included for identification only.

Storage: plain git, not LFS. 23 images (14 SVG, 9 PNG) plus the manifest total about 260 KB, the largest file under 512 KB. SVG is text and diffs well. LFS would need lfs: true in CI checkout and would break bun install from a git dependency and npm packaging for a few hundred KB.

Cleanup and failure mode

Sandboxes never wait for manual cleanup, and a dead daemon never leaves them running. Each owner (Longshore's server, Turntable's daemon, any tool) cleans up only what it labelled, on its own tick. berth gives it two primitives and keeps the policy out: the owner says what is live, berth carries out the bounded actions.

  1. Label at create with the owner's label (for example ls.run, turntable.run, scurry.pool).
  2. createDefaults(provider, owner, runCapMin) returns the failure-mode create parameters: the owner labels, an auto-stop ttlSec greater than 0 (never 0, which disables it) at no more than the run cap plus grace (10 min by default), and autoDeleteOnStop. unmet lists what the provider cannot honour; check it is empty.
  3. reap(provider, policy) on every tick.
import { createDefaults, reap } from "@nc9/berth-sdk";

const owner = { label: "ls.fleet", value: "fleet-1" };

// At create: these keep working when the daemon is dead.
const d = createDefaults(provider, owner, 120);
if (d.unmet.length) throw new Error(d.unmet.join("; "));
await provider.create({
  source,
  egress,
  ...d.spec,
  labels: { ...d.spec.labels, "ls.run": runId },
});

// On every tick.
const report = await reap(provider, {
  owner, // required; without it reap refuses
  classify: (sb) =>
    myRuns.isLive(sb.labels["ls.run"])
      ? "live"
      : myRuns.knows(sb.labels["ls.run"])
        ? "terminal"
        : "unknown",
  runCapMin: 120, // maxStartedMin defaults to runCapMin + 10; or set maxStartedMin
  dryRun: false, // the default is true: report only
});
  • Scope: only sandboxes carrying exactly owner.label = owner.value are touched. Other owners and unlabelled sandboxes never are.

  • Classes (each adapter maps its own states onto neutral phases; a state it cannot place is unknown and is never acted on):

    Class When Action
    error provider reports an error state delete
    stuck_transitional starting, stopping, archiving, restoring or building past transitionalTimeoutMin (30) delete
    overrun started past maxStartedMin while classify says live stop_then_delete
    owner_terminal classify says terminal stop_then_delete
    orphan classify says unknown stop_then_delete
    archived_expired archived longer than archivedRetentionMin (0: delete) delete
  • Report: counts and vCPU per class, plus ids and names (never env, secrets or labels), and a result per sandbox. It executes only when dryRun is false.

  • Bounded and re-checked: at most maxActions (25) per call; the rest wait for the next tick. Each action re-reads the sandbox with a fresh get() and is skipped if it vanished, was relabelled, changed phase or no longer falls in the same class.

  • classify failures keep the sandbox: a throw or an invalid answer is never treated as unknown.

  • Adapters: a provider takes part by exposing lifecycle (list, get, stop, delete, autoDeleteOnStop). The Daytona adapter (@nc9/berth-daytona) and the conformance fake do; runReapConformance in @nc9/berth-conformance checks any adapter.

Data rules

  • Every price rate carries verifiedAt, a sourceUrl (https) and, where the vendor states one, the raw value and unit (raw) so conversions can be audited.
  • Nothing is invented: a field the provider does not document is marked unverified (for example status: "unverified", freeTier: "unverified").
  • Validators: validateProvider, validateContainerType and validateProviders return arrays of error strings.
  • No policy: berth reports facts. Trust tiers, ownership rules and ceilings belong to the consumer.

Status: design. See DESIGN.md.

Licence: MIT.

About

Container and sandbox provider registry and SDK: providers, container types, capabilities and prices, one interface (shared by Longshore and Turntable)

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages