Introducing a new way to review your PRs.

Read the announcement

superradcompany / microsandbox

🧱 easy, fast, programmable and local-first microVM runtime and library

View on GitHub

27 documents · Updated Nov 23, 2026

docs / service-management-apis

Service management APIs

Service management APIs control public URLs that route traffic to sandbox ports. The cloud service model keeps one named service bound to a target sandbox and port, then exposes the same create, read, list, update, enable, disable, refresh, and remove lifecycle across the Rust SDK, language adapters, generated data types, and CLI.

Service resource model

The CloudService resource represents one public endpoint owned by an organization. Its stable identity is a globally unique slug. Its state includes the public URL, the current target, status, and creation and change times. A target is the pair of a sandbox name and a port that receives requests (packages/…/services.rs• L10-29, packages/…/services.rs• L49-58).

Service states

The service status tells callers whether the public URL routes traffic and whether a target is still attached. A disabled service keeps its target but does not route requests. A detached service has no target and must receive a new target before it can be enabled (packages/…/services.rs• L31-47).

StatusMeaningTarget
enabledRoutes requests to the targetPresent
disabledKeeps the target without routing requestsPresent
detachedHas no targetAbsent
unknownContains a status not known by this SDKDepends on the returned data

References: packages/…/services.rs• L31-47 sdk/…/service.ts• L138-152

Service targets

A service target identifies the running sandbox port that receives requests. Create and update operations require a valid target, and setting a target also enables or reattaches the service (packages/…/services.rs• L60-82, sdk/…/service.rs• L242-259).

The service URL is public, but the service resource does not replace the sandbox. It provides a cloud-managed route to that sandbox port. The target can change while the service slug and URL remain the resource identity.

References: packages/…/services.rs• L49-68 sdk/…/service.ts• L164-180

Service lifecycle

The lifecycle moves a service from creation through routing changes and ends with removal. Read operations return the service state known at that request. Change operations return a new service value after the cloud reports success, so callers can replace their old value when they need the new state.

When an actor processes a service request, it follows this high-level sequence:

flowchart LR
    A[Service slug and target] --> B[Create service]
    B --> C[Enabled public URL]
    C --> D[Update target]
    D --> C
    C --> E[Disable]
    E --> F[Disabled service]
    F --> G[Enable]
    G --> C
    F --> H[Remove]
    C --> H
    H --> I[Slug released]
    C --> J[Detach through service state]
    J --> K[Detached service]
    K --> D

References: sdk/…/service.rs• L23-76 sdk/…/service.rs• L66-87 crates/…/service.rs• L42-67

Service reads and pages

The read interface supports lookup by slug and ordered listing. Listing can filter by target sandbox and uses an opaque cursor with a page limit. Each page carries the services and the cursor for the next page (sdk/…/service.ts• L18-22, sdk/…/service.ts• L60-86).

The CLI hides page handling from its users. Its list command requests pages until no cursor remains, then prints a complete table or JSON array (crates/…/service.rs• L218-234, crates/…/service.rs• L281-305). SDK callers must follow nextCursor or next_cursor when they need all services.

References: sdk/…/service.rs• L131-160 sdk/…/service.ts• L112-126 crates/…/service.rs• L218-234

Service changes

Create attaches a slug to an initial target. Update moves the target and also enables or reattaches the service. Enable and disable change routing without changing the slug. Remove deletes the service and releases the slug (crates/…/service.rs• L160-209, crates/…/service.rs• L236-241).

The cloud API treats each change as a single operation. SDKs do not retry a change automatically. If the result is unknown, the caller must read the service and inspect its current state before trying again (sdk/…/service.rs• L265-335, sdk/…/service.ts• L164-191).

References: sdk/…/service.rs• L52-87 sdk/…/service.rs• L293-365 docs/…/service-commands.mdx• L11-13

Cross-language interfaces

The interfaces share one service contract while adapting naming, async behavior, values, and errors to each language. The Rust SDK is the central resource API. Native bindings expose that API to Node.js, Python, Ruby, and Go. Generated cloud types keep request and response fields aligned across these surfaces (packages/…/services.rs• L10-82).

Rust SDK interface

The Rust SDK exposes service lifecycle operations through a cloud backend. Its resource abstraction carries the backend that returned it, which keeps later changes and refreshes tied to the same cloud context. The local backend refuses all service operations because services are cloud-only (sdk/…/service.rs• L1-27, sdk/…/service.rs• L83-141).

The Rust service API is the contract that the other language adapters consume. Its list builder expresses sandbox, cursor, and limit filters. Its typed service errors distinguish a refused change from a change whose final state cannot be known (sdk/…/service.rs• L131-175, sdk/…/service.rs• L337-414).

See Rust SDK for the wider Rust client model.

References: sdk/…/service.rs• L23-76 sdk/…/service.rs• L94-205 sdk/…/service.rs• L337-414

Native binding interface

Native bindings translate language calls into the shared Rust service API. They preserve the service fields, page shape, lifecycle actions, and change state while converting errors into the host language. Node.js uses a native service object, Python uses an async native class, Ruby exposes wrapped service objects, and Go calls the native layer through a C-compatible interface (sdk/…/service.rs• L14-46, sdk/…/service.rs• L14-27, sdk/…/services.rs• L19-27, sdk/…/service.rs• L32-70).

The binding boundary also carries handles where the host language needs a stable native resource. In Go, a service value keeps the native handle that owns its backend context. Closing the handle prevents later requests but does not remove the cloud service (sdk/…/service.go• L12-27, sdk/…/service.go• L194-236).

See language binding adapters for the shared adapter approach.

References: sdk/…/service.rs• L52-104 sdk/…/service.rs• L32-100 sdk/…/services.rs• L163-234 sdk/…/service.rs• L83-166

Generated type interface

The generated type layer defines the cloud wire contract used by the backend and language bridges. It names the service fields and status values, describes create and update bodies, and emits compatible schema forms for API and language consumers. Update requests reject unknown fields so a partial or misspelled change is not silently applied (packages/…/services.rs• L60-82).

The same contract keeps absent targets consistent across languages: Rust uses an optional target, TypeScript and Go expose a nullable target, and Python and Ruby map it to their host-language empty value. Status values use lower-case wire names such as enabled, disabled, and detached (packages/…/services.rs• L31-47, sdk/…/service.ts• L15-16, sdk/…/service.go• L11-20).

References: packages/…/services.rs• L10-82 sdk/…/service.go• L5-44 sdk/…/service.ts• L9-22

CLI interface

The msb service command presents the lifecycle as direct operational commands. It supports create, update, enable, disable, inspect, list, and remove. JSON output uses the service record shape so scripts can consume the same identity, routing state, target, URL, and timestamps as SDK callers (crates/…/service.rs• L28-67, docs/…/service-commands.mdx• L9-13).

The CLI requires a cloud backend and gives local-backend failures a setup hint. It accepts targets as SANDBOX:PORT, while SDKs represent the same value as a target object or type (crates/…/service.rs• L20-22, crates/…/service.rs• L70-98, crates/…/service.rs• L248-264).

See command-line interface for the wider CLI model.

References: crates/…/service.rs• L20-38 crates/…/service.rs• L42-67 crates/…/service.rs• L248-278 docs/…/service-commands.mdx• L15-99

Error and outcome contract

Service errors describe both why a change failed and whether the caller can know that no change occurred. A normal refusal is unchanged. A transport or server result after the request may be unknown, which requires a read before a retry. The adapters preserve this distinction for their host languages (sdk/…/service.rs• L293-365, sdk/…/service.rs• L290-340).

Common service-specific conditions include quota limits, conflicts, detached services, unreachable or stopped targets, paused changes, and unknown outcomes. Retry timing can accompany temporary conditions. An unrecognized refusal keeps its raw code, status, and message so a newer cloud rule is not hidden (docs/…/services.mdx• L398-470).

References: sdk/…/service.rs• L390-426 sdk/…/service.rs• L290-330 docs/…/services.mdx• L398-470

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the generated cloud fields and status strings aligned with every native binding and CLI JSON record.
  • Keep nullable or absent targets mapped consistently between the wire type and each host language.
  • Preserve the unchanged versus unknown change state when adding or mapping service errors.
  • Keep list cursor names and page semantics aligned between SDKs and the CLI's page collector.
  • Keep cloud-only behavior aligned between the Rust backend, native error mapping, and CLI guidance.

Important failure modes

TriggerConsequenceGuard
Change response is lost after the request is sentThe service state may have changed while the caller sees an errorRead the service before retrying
Service uses a detached or stopped targetEnable or route change is refusedSet a running target or start the sandbox
Local backend receives a service operationNo cloud request is madeSelect a cloud backend and API key
Caller stops listing after one pageServices after the first page are missedFollow the returned cursor
Caller sends an unknown update fieldThe whole update is rejectedUse the shared generated update shape

Key files

FileWhy to read it
packages/…/services.rsDefines the shared service resource, target, status, and request shapes
sdk/…/service.rsShows the cloud-only lifecycle contract
sdk/…/service.rsShows the cloud operations, paging, and change outcome rules
sdk/…/service.tsShows the public object and builder interface in TypeScript
sdk/…/service.rsShows the native boundary for the TypeScript SDK
sdk/…/service.rsShows the cross-language FFI payload and error contract
sdk/…/service.goShows Go's service handle and public lifecycle API
sdk/…/service.rsShows the Python async service surface
sdk/…/services.rsShows the Ruby service and builder surface
crates/…/service.rsShows CLI commands, full-list paging, and local-backend guidance
docs/…/service-commands.mdxDescribes the user-facing CLI behavior and output