Maritime

Short-lived Firecracker VMs with native binary files, file watches, private previews, memory snapshots and account template builds.

Install and authenticate

pnpm add sbox-sdk maritime-sdk@~0.13.0
export MARITIME_API_KEY=mk_...

Use an account key with sandboxes or manage scope. A trial or paid plan is required to create VMs. MARITIME_API_URL optionally overrides https://api.maritime.sh. Both variables are read by the native SDK when factory options are omitted. client.verify() authenticates a single list request and never creates a VM.

The adapter and its mapped APIs support Node 20.10+. Importing sbox-sdk/maritime does not import maritime-sdk until an API operation. The raw SDK's interactive terminal requires a global WebSocket, normally Node 22+, and is not exposed by the unified adapter because its close event lacks an exit code.

Quickstart

import { createSandboxClient } from "sbox-sdk";
import { maritime } from "sbox-sdk/maritime";

const client = createSandboxClient({
  provider: maritime({ timeLimitMinutes: 30 }),
});
const sandbox = await client.create({
  template: "python",
  env: { TASK: "example" },
  metadata: { project: "demo" },
  lifecycle: {
    idleTimeoutMs: 5 * 60_000,
    onIdle: "destroy",
  },
});
try {
  const result = await sandbox.commands.run("echo $TASK");
  await sandbox.files.write("/tmp/result.txt", result.stdout);
} finally {
  await sandbox.destroy();
}

The native adapter provides egress allowlists, cursor listing, file watching and templates beyond an E2B preset. Existing sbox-sdk/e2b applications can also use Maritime's E2B-compatible API with domain sb.mtm.sh, but that adapter's capabilities do not describe this native adapter.

Capabilities

CapabilityLevelNotes
streamingemulatedpolls retained stdout and stderr of a native background command every 100 ms
background / killProcessnativebackground commands with a native ID; SIGTERM and SIGKILL
listnativeall ephemeral cursors; metadata and state filtered client-side
filesUploadnativebinary file API, 5 MB round trip
filesWatchnativerecursive only; rename becomes delete plus create
exposePort / privatePreviewnativesubdomain URLs; private previews carry a ?token= query token
egressControlnativeallow-all, block-all or hostname allow-list; no CIDRs, deny or injection
pausenativekeeps disk, memory and processes (preservesMemoryOnPause)
setTimeoutnativerestarts the running-time limit, 5-1440 minutes
snapshotnativedisk and memory together; filesystem-only mode is rejected
codeInterpreter / statefulKernelnativePython only, needs template: "code-interpreter"
templateBuildnativeDockerfile or public image, built in your account
metricsnativeCPU, memory and disk usage
stopunsupporteduse pause, or destroy
stdin / pty / sshunsupportedbuffered stdin is handled by the core
fork / volumes / region / gpu / proxiedFetch / secretsVaultunsupported

Flags: perCommandEnvCwd: true, exitCodeNative: true, preservesMemoryOnPause: true, previewModel: "subdomain", previewBrowserAuth: true, templateSources: ["dockerfile", "image"], idempotency: "exact".

How the spec maps

RequestMaritime mapping
template, templateRef, fromSnapshotfrom, accepting a stock/customer template, saved snapshot name or public OCI reference. Foreign template refs and conflicting sources are rejected.
name, metadata, envNative fields. Creating a live name returns the existing VM; getOrCreate uses this atomic API behavior.
idempotencyKeyNative Idempotency-Key header; call-context key takes precedence.
resources.vcpusWhole vCPU count 1–16.
resources.memoryMB1024–65536 MiB in multiples of 1024.
resources.diskMB5–500 GiB in whole GiB, converted by dividing by 1024.
lifecycle.idleTimeoutMsidleMinutes, whole minutes 1–60. Default 5.
lifecycle.maxAgeMs, deprecated ttlMsRejected: Maritime cannot enforce a hard deadline across pauses. Use the provider option timeLimitMinutes for its native running-time budget, whole minutes 5–1440. Default 1440.
lifecycle.onIdlepause, or destroy mapped to kill. stop is rejected.
lifecycle.autoResumeAlways enabled; false is rejected.
networkallow-all, block-all, or hostname allow-list including wildcards.
previewVisibilityDefault for previews created by this handle. A private default stays private.
ports, region, volumes, secrets, GPU and shmMBRejected before creation. Use ports.expose() afterwards. Inline env is not a provider secret vault.
Network CIDRs, deny rules, header injectionRejected at create and at runtime.

Create contract

  • Idempotency is exact. Every create sends an Idempotency-Key: the client's key, or a random one when you call getOrCreate. Maritime replays the same VM for a repeated key, and a live name is unique, so creating it again returns the existing VM. A create that times out is therefore retried by the client without risking a second VM.
  • Sizing is applied as given. vcpus, memoryMB, diskMB and idleTimeoutMs are exact, with no rounding. Values off the native grid are rejected with a Validation error instead of being snapped: whole vCPUs 1-16, memory in multiples of 1024 MB (1-64 GiB), disk in whole GiB (5-500 GiB), idle timeout in whole minutes (1-60).
  • Rejected fields. shmMB, gpu/gpuCount and lifecycle.maxAgeMs (and the deprecated ttlMs) throw Validation before any request. No field is ignored, so strictSpec changes nothing here.
  • Limits. None are declared. Maritime documents no cap on metadata entries, and ports in the spec are rejected outright (expose ports after creation).
  • Sizes. spec.size expands through the default ladder into exact custom resources, since Maritime accepts any vCPU, memory and disk within the ranges above. Maritime's own small/medium/large/xlarge presets are not used, and small there is 2 vCPU, 4 GiB, 12 GB.

Lifecycle and limits

The idle timer and time limit are separate. Going idle either ends the VM and its disk or pauses it. Pause retains disk, memory and processes, and a data-plane call or preview request resumes it. resume() sends a foreground no-op. destroy() calls the permanent ephemeral kill endpoint; ended records may remain available for audit, but their VM and disk are gone.

Maritime's time limit counts running time and restarts after resume. maxAgeMs and its deprecated alias ttlMs are rejected because the service cannot enforce their absolute wall-clock deadline across pauses. The provider option timeLimitMinutes explicitly selects Maritime's running-time budget. setTimeout(ms) restarts the time limit from that call, without changing the idle timer. Applications requiring an absolute deadline must destroy the VM at their own deadline.

Default resources are 2 vCPU, 4 GiB memory and 12 GiB disk. Plan awake-at-once limits and capacity apply. See current limits for plan ceilings. Auth, not-found, conflict, quota and command timeout errors use the common SDK error codes. Billing gates map to retryable QuotaExceeded.

getInfo() reads live state: starting/resuming → creating, running → running, pausing → suspending, paused → paused, ended → destroyed, error → error. Listing traverses all ephemeral cursors and filters metadata and state before applying the limit. The API lists live VMs, including ones made with the native or E2B APIs, and excludes swarms.

Commands and files

Commands start with native background execution so the adapter can kill their native ID. The adapter polls separate retained stdout and stderr every 100 ms and emits new chunks, so streaming is emulated. Exit codes, cwd, env and command kill are native. timeoutMs is passed in rounded-up seconds, at most 3600, and a local timer enforces the requested millisecond deadline. Abort before startup prevents execution; abort while startup is pending kills the process as soon as its ID arrives. Cancellation cleanup errors are retained and reported by destroy().

Polling waits count as data-plane activity. Detached native jobs alone do not keep VMs awake. Command output is bounded by Maritime's retention limit. If the API reports truncation, the adapter raises an error instead of silently returning incomplete output. Interactive stdin and PTY are unsupported; buffered stdin is handled by the core.

Reads, writes, directory lists, uploads and removal use the native binary file API, including 5 MB files. Other filesystem operations use the core's shell fallback. Native recursive file watches are available through files.watch(path, callback, { recursive: true }); rename becomes delete plus create. Watch stream errors are reported on destroy().

Python code execution and named kernel contexts require template: "code-interpreter". Other languages and a context cwd are rejected. Native rich outputs and errors are retained.

Previews

const preview = await sandbox.ports!.expose(3000, { visibility: "private" });
// preview.auth = { type: "query", param: "token", token: "..." }

Private URLs contain ?token=..., usable by browsers and browser WebSockets with the same host and wss: scheme. Public previews call the native URL API with token: false. Tokens are sensitive; do not log or publish private URLs. Browser WebSocket behavior follows the provider's URL-token contract; no authenticated live browser test was run for this adapter. Port revocation and port enumeration are not exposed.

Snapshots and templates

Snapshots use save(name) and include disk and memory. Filesystem-only mode is rejected. Restore creates a new VM with client.create({ fromSnapshot: ref }); in-place restore and fork are unsupported. Snapshot listing filters by source VM, and deletion uses the account snapshot API.

const template = await client.templates!.build({
  name: "python-tools",
  source: { dockerfile: "FROM python:3.12\nRUN pip install requests\n" },
  resources: { vcpus: 2, memoryMB: 4096, diskMB: 12 * 1024 },
});
const worker = await client.create({ template });
await worker.destroy();

Builds stay in the user's account. A public source.image is converted to a Dockerfile FROM; the Dockerfile includes the full core cache key as a reserved comment. This lets lookup recover provenance across processes without treating stock templates as cache hits. Exact template ID or name takes precedence over cache-key matches. Only ready templates are returned. The core emits the final ready event; the adapter emits building progress.

Context uploads, private registry authentication, snapshot template builds and separate template env/workdir/user options are rejected. Put these settings directly into a context-free Dockerfile. startCmd and readyCmd are passed natively. Template size is fixed by Maritime. Reusing a taken name with different content returns a conflict; force build does not delete an existing template. Aborting the local wait leaves an already submitted remote build running.

The offline suite runs the published SDK against a MiniShell-backed fake transport. Live VM creation, account quotas, VM memory restoration, browser preview upgrades, file watch delivery and actual template builds need account credentials and remain unverified against Maritime.

For a separate, explicitly paid template build/boot/delete check, set MARITIME_API_KEY, SBOX_LIVE=maritime and MARITIME_LIVE_TEMPLATES=1, then run from packages/sbox-sdk:

pnpm exec vitest run -c src/maritime/vitest.templates.config.mjs

This check deletes its test VM and template in cleanup. The ordinary live conformance config does not build a template. No template check runs without all three environment gates.

On this page