Skip to main content
A Service gives a sandbox port a public HTTPS URL. Requests to the URL go to the Service’s target: one sandbox and port. The URL is https://<slug>.<domain> and stays the same when you change the target.

Create a Service

Select a remote destination with MSB_BACKEND=remote or a remote profile. With the local destination selected, Service lookup, list, and creation return an unsupported error before sending a provider request, even when MSB_API_KEY is set. Start the target sandbox, then create the Service:
Slugs contain 3–63 lowercase letters, digits, and single hyphens. They cannot start or end with a hyphen and are not normalized. If a slug is unavailable, choose another. Repeating a create with the same slug and target returns the existing Service while it is enabled. Use the returned URL as-is. Service URLs are public, so add authentication in your application when needed. The URL usually works when create, enable, or a target change returns; sometimes it takes a few more seconds. A URL requested shortly before you created the Service or set its target can return 404 not_found for a short time.

Move, disable, or enable a Service

A Service is enabled, disabled, or detached (it has no target). Disabling keeps the target. Enabling the Service, or setting a target, turns it back on; the target sandbox must be running.
Each call returns the updated Service. Enabling and disabling both need a target: on a detached Service, both fail with the service_detached reason, so set a target instead. If the target sandbox stops, the Service keeps its target and requests return 503 sandbox_not_running until the sandbox runs again. If the target sandbox is removed, the Service becomes detached and keeps its slug. After a few seconds, requests return 503 no_target or 404 not_found until you set a new target.

Handle requests

In the sandbox, your application must listen on the target port at 0.0.0.0 or 127.0.0.1. Services support HTTP, WebSocket, and server-sent events (SSE). Set your own timeouts for slow responses, and keep long-lived connections active. Your application receives the original method, path, query, and body, plus these headers:
  • Host: the Service hostname
  • X-Forwarded-Host: the Service hostname
  • X-Forwarded-Proto: https
  • X-Forwarded-For: the client IP address
Microsandbox sets these headers itself and replaces any copies the client sent, so your application can trust them. Header names starting with msb- or x-msb-, and cookies named msb_* or __Host-msb_*, are reserved for Microsandbox: they never reach your application, and your responses cannot set those cookies. On the Free plan, a browser’s first visit shows a notice page before your application. Automated browsers, such as end-to-end tests, can skip it by sending an msb-skip-browser-warning header with any value.

Error responses

When Microsandbox answers instead of your application, the response has an x-msb-error header. Microsandbox removes this header from your application’s responses, so it always means Microsandbox answered. The body is JSON with the same code in error.code, or an HTML page when the client asks for text/html. Only service_unavailable means Microsandbox itself cannot serve the request. The other codes describe the Service, its target sandbox, your application, or the request.

Get a Service

Get a Service by its slug to read its URL, its status (enabled, disabled or detached), its target, and when it was created and last changed. A Service object holds the state from the response that returned it; refresh returns a current copy.
For scripts, add --format json to any msb service command except remove. A Service prints as an object with slug, url, status, target, created_at, and updated_at.

List Services

Lists are in slug order and include disabled and detached Services. Filter by sandbox to find its Services.
The SDKs return one page at a time: 20 Services by default, up to 100 with a limit. Pass a page’s next cursor to get the following page; the last page has none. msb service ls lists every Service.

Remove a Service

Removing a Service releases its slug.

When a change fails

Create, update, enable, disable, and remove each send one request and never retry. Most errors mean nothing changed. If an error says the change may have been applied, get the Service and check it before trying again. An update, enable, or disable that is already in effect succeeds without a change. See SDK errors.

Audit events

Each committed Service change records one event in the organization’s audit log. A change that is already in effect records nothing. Read Service events with the audit-log API. Authenticate with an API key.
You can also filter with since, until, cursor, and limit. Each event has id, org_id, category (audit), event_type, actor, payload, and timestamp. Every payload also has org_id. A service_rotated event means the Service was pointed at a new target. Its from_sandbox_id is null when the Service had no target. The sandbox_id on service_disabled and service_enabled is null when the target sandbox was deleted during the change. On service_deleted, it is null when the Service was detached. Events contain sandbox IDs, not sandbox names. Deleting a target sandbox automatically detaches its Service without recording a service_* event.

Limits

You can request a higher limit for your organization. If a limit drops below your current usage, existing Services keep working; creating a Service, or moving one to a sandbox at its limit, is refused until you are under it.Going over these limits fails with service_quota_exceeded or sandbox_service_limit_exceeded (see Service changes). Disabled Services count toward both limits, and detached Services count toward the organization limit. Too many concurrent requests to one sandbox return 429 service_busy_inflight.