Skip to navigation

Create a sandbox

Starts a sandbox from a registry image (image) or from an image you built (image_id). The call returns 202 at once with status: creating. Then do one of three things:

  • Poll GET /v1/sandboxes/{sandbox_id} until status is running or failed.
  • Add ?wait=true to hold this request until then, for up to wait_timeout_seconds. If the wait ends first you still get 202 with creating, and the create continues.
  • Set webhook_url and wait for the sandbox.running event.

The status code is 202 in every case, also when wait=true returns a sandbox that is running or failed. Read status in the body.

Vendor choice and fallback. Meadow tries vendors in the order given by provider.order, else the project’s routing.sandboxes.order, else daytona then modal. It skips vendors the account has no key for. If a vendor cannot meet the request, refuses, has no capacity, or misses provider.create_timeout_seconds, Meadow tries the next one. Each try is recorded in attempts. If every vendor fails, the sandbox ends as failed with a failure_reason. The HTTP status stays 202 or 200, so read the sandbox body. A vendor that failed lately on this account can be moved to the end of the route while it cools down (sandbox_health on GET /v1/provider-keys). An order you set (provider.order, or the project’s routing.sandboxes.order) is tried as written unless its first vendor answered quota exceeded or no capacity for this account, or failed 3 creates in a row within 10 minutes, and its cooldown has not ended. A route with no order moves any vendor that is cooling down. A route with one vendor is never changed. Every move is listed in skipped_providers. A vendor that rejects the stored key (401 or 403) fails its attempt at once, the next vendor is tried, and the rejection does not count against the vendor’s health. On a project with routing.lock, a request that sends provider.order, provider.only, provider.allow_fallbacks, provider.create_timeout_seconds or provider.options returns 403.

Retries. Send Idempotency-Key so a retry cannot create a second sandbox.

Rules.

  • Exactly one of image and image_id is required.
  • Unknown fields return 400, and so does a known field set to null. The removed fields model_access, sandbox_access, and provider_options return 400. To let code in the sandbox call Meadow, mint a narrow key with POST /v1/keys and pass it in env.
  • provider.options is checked for every vendor in the route before any is tried, so a bad option fails the request even when another vendor could serve it.
  • resources are honoured on both vendors, but the units differ and Meadow does not convert them: cpu counts virtual CPUs on Daytona and physical cores on Modal. On Modal cpu and memory_mb are hard limits unless you send provider.options.modal.burst: true. A size or GPU type a vendor cannot serve skips that vendor with an unsupported attempt that carries the reason. See resources.
  • The response does not echo image, image_id, env, timeout_seconds, idle_timeout_seconds, or webhook_url. Keep them on your side if you need them later. network is returned.

Scope: sandboxes.

curl -sS -X POST "$MEADOW_BASE_URL/v1/sandboxes?wait=true" \
-H "Authorization: Bearer $MEADOW_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"image":"python:3.12-slim","timeout_seconds":1800}'

Authentication

AuthorizationBearer

A Meadow API key, sent as Authorization: Bearer mdw_.... The header x-api-key: mdw_... is accepted in its place.

Headers

Idempotency-KeystringOptionalformat: "^[ -~]+$"1-255 characters

Makes a retry safe. A repeat with the same key and the same body returns the result of the first call instead of starting again. The same key with a different body returns 409. On POST /v1/keys, POST /v1/projects and POST /v1/images a value is scoped to the API key that sent it: another key that sends the same value starts its own request. The sandbox and exec routes scope it to the API key too. On the exec route the header only has an effect with background: true. See Idempotency in the introduction for how long a value is kept.

The key is 1 to 255 bytes of printable ASCII. A blank, longer, or non-ASCII key, or the header sent twice, returns 400. A UUID works well.

Query parameters

waitbooleanOptionalDefaults to false

When true, hold the request until the sandbox is running or failed, or until wait_timeout_seconds passes.

wait_timeout_secondsintegerOptional<=900Defaults to 300

Longest time to hold the request when wait is true, in seconds, from 1 to 900. A value outside that range returns 400. The create continues after the wait ends.

Request

At most 1 MiB.
namestringOptional
A label for people. It need not be unique. Must not be empty when sent.
imagestringOptional

A registry image both providers can pull, with its tag. On Modal the image’s default command must keep running. If it exits, the sandbox becomes failed with provider_lost.

image_idstringOptional

An image built with POST /v1/images. Providers where its build is ready start at once. A provider with no build yet builds it first, which counts toward create_timeout_seconds. A provider whose build failed is skipped.

Daytona fixes resources on a snapshot. Meadow keeps one Daytona snapshot per image and size (cpu, memory_mb, disk_mb, GPU count and type). The first sandbox that asks for a new size makes the snapshot from the image’s own build, which counts toward create_timeout_seconds, and the served attempt’s detail says provider built a copy of the image for this size. Later sandboxes of that size start at once. A size Daytona cannot serve skips Daytona with an unsupported attempt that carries Daytona’s reason.

registry_authobjectOptional

Login for a private image. Both fields are required when it is sent. Cannot be combined with image_id. Daytona does not support it and is skipped.

resourcesobjectOptional
The size of the sandbox. Unknown fields return 400.
envmap from strings to stringsOptional
Environment variables for every command in the sandbox. Keys must not be empty. Values are never returned by the API.
timeout_secondsintegerOptional<=86400Defaults to 3600

Longest lifetime, in seconds, from 1 to 86400 (24 hours). The sandbox is terminated when it passes. Meadow enforces this itself. Where the provider has its own lifetime setting, Meadow sets that too, so the sandbox still ends if Meadow is down. A value above 86400 returns 400. A value below 10 skips Modal. The default is one hour, so a long job must send this field. Nothing else in Meadow ends a running sandbox earlier, apart from idle_timeout_seconds when you send it, and a spent dollar limit on a key with limit_action stop_sandboxes. A vendor whose own lifetime limit for your account is lower than timeout_seconds is skipped with an unsupported attempt that says so (checked on Daytona, which reports the time it will end a sandbox).

idle_timeout_secondsintegerOptional

Terminate after this many seconds with no API call for the sandbox and no background command running. At least 1. Left out, the sandbox never ends for being idle. A foreground or streamed exec call, a file upload, and a file download count as activity for as long as they are open.

portslist of integersOptional

Ports inside the sandbox to make reachable from outside. They must be listed here: a port cannot be opened after create. Get the address with GET /v1/sandboxes/{sandbox_id}/ports/{port}.

sshbooleanOptionalDefaults to false

Make the sandbox reachable over SSH. It must be set here: SSH cannot be turned on after create. Get the address and key with POST /v1/sandboxes/{sandbox_id}/ssh.

networkobjectOptional

Outbound network rules. Left out, outbound traffic is open. block_all cannot be combined with the allow lists. On Modal block_all also blocks inbound connections, so Modal is skipped for block_all with ports or ssh: true. Daytona cannot combine allow_domains with allow_cidrs, takes at most 10 allow_cidrs entries and 100 allow_domains entries, and takes IPv4 ranges only. It is skipped for a request outside those limits. The rules can be replaced later with PATCH /v1/sandboxes/{sandbox_id}. On Modal that works only for a sandbox created with allow_domains or allow_cidrs: see that operation.

providerobjectOptional

Which sandbox providers may host a sandbox, and in what order. Send it as provider on POST /v1/sandboxes, or store it on a project as routing.sandboxes. A field set on the request replaces the same field from the project. A provider that cannot meet the request (GPU type, lifetime, network rule, private registry) is skipped and recorded in attempts as unsupported.

labelsmap from strings to stringsOptional

Your own key and value pairs, returned with the sandbox and usable as a filter on GET /v1/sandboxes. Keys must not be empty.

webhook_urlstringOptionalformat: "uri"

Where to send this sandbox’s status events. Must be https and resolve to a public address. Left out, the project’s webhook_url is used.

Response headers

x-request-idstringOptional

Meadow’s id for this request, req_ and 24 hex characters. Every response carries it, including errors, streams and unknown routes. Every error in the Error schema repeats it as request_id. Quote it when you report a problem.

Idempotent-ReplayedenumOptional

true when this response is the saved result of an earlier request with the same Idempotency-Key. Absent on a first response. Sent by POST /v1/keys, POST /v1/projects, POST /v1/images, POST /v1/sandboxes and a background POST /v1/sandboxes/{sandbox_id}/exec. On the two sandbox routes the body is the sandbox or the command as it is now.

Allowed values:

Response

Accepted. Without wait the sandbox is creating. With wait=true it is usually running or failed.

idstring
The sandbox id.
project_idstring
The project the sandbox belongs to.
statusenum
  • creating: accepted. Meadow is trying vendors.
  • running: ready for exec, file, port, and SSH calls.
  • terminating: delete was asked for and the vendor has not confirmed yet.
  • terminated: ended by delete, by timeout_seconds, by the idle timeout, or by the vendor at its own lifetime limit.
  • failed: no vendor could create it, or the vendor lost it while it ran. See failure_reason.
Allowed values:
created_atdatetime
When the create call was accepted.
namestring or nullOptional
The label given at create. Null when none was given.
failure_reasonenumOptional

Why the sandbox is failed. Null otherwise.

  • all_providers_failed: every provider in the route failed, for mixed reasons. Read attempts.
  • timeout: every attempt timed out.
  • image_pull_failed: every attempt failed to pull the image.
  • build_failed: every attempt failed to build the image.
  • provider_lost: the sandbox was running and the provider lost it, for example because the image’s main command exited on Modal.
  • internal: Meadow failed.
providerenum or nullOptional
The provider hosting the sandbox. Null until one accepts it.
Allowed values:
provider_sandbox_idstring or nullOptional
The vendor's own id, for finding the sandbox in their dashboard.
attemptslist of objectsOptional
Every try to create the sandbox, in order. Empty until the first try ends.
skipped_providerslist of objectsOptional

Providers Meadow moved to the end of the route because their circuit breaker was open (sandbox_health on GET /v1/provider-keys), in the order it moved them. Empty when the route was tried as written. A moved provider is still tried if every provider before it fails, and then it also appears in attempts.

The order is decided when the create is about to try a provider, after POST /v1/sandboxes has answered 202. So this list is filled on the answer of a wait=true create, on GET /v1/sandboxes/{sandbox_id} and in webhook events, and is empty on the first 202 of a create that does not wait.

resourcesobjectOptional
The size of the sandbox. Unknown fields return 400.
labelsmap from strings to stringsOptional
The labels given at create. Empty when none were given.
portslist of integersOptional
The ports listed at create.
sshbooleanOptional
Whether SSH was asked for at create.
networkobject or nullOptional

The outbound network rules in force: the rules given at create, or the rules of the last PATCH /v1/sandboxes/{sandbox_id}. All three fields are always present. Null for a sandbox created before Meadow recorded the rules.

started_atdatetime or nullOptional

When the sandbox became running. Null before that.

expires_atdatetime or nullOptional

When timeout_seconds ends the sandbox: started_at plus the timeout. Null until it is running.

terminated_atdatetime or nullOptional

When the sandbox became terminated. Null otherwise.

costobjectOptional

What this sandbox costs at the vendor, so far. Returned by GET /v1/sandboxes/{sandbox_id} and GET /v1/sandboxes, and left out of the other sandbox responses. It is read from the usage records with the same arithmetic as GET /v1/usage, so the two agree: this object covers every vendor sandbox the create started, a provider that Meadow moved on from included, and its cost is what sandbox_cost in /v1/usage adds up for this sandbox over its whole life.

It is a list price times time, not the vendor’s invoice. cost_status says how far to trust it:

  • price_table: the size the vendor granted times its list price.
  • price_estimated: an estimate. cost_reason says why: grant_unconfirmed (the vendor has not yet confirmed the size, so the size asked for is priced), spot_unconfirmed, or meadow_clock (the sandbox has ended and its time is still Meadow’s own count, which runs longer than the vendor’s: Meadow has not yet read the time the vendor billed), or vendor_window_unavailable (the same, and Meadow can no longer read that time: the account stores no key for the vendor, or the sandbox ended more than 4 days ago). A reason about the price is shown before either when both apply.
  • price_unknown: no cost can be stated, and cost is null. Unknown never means free. cost_reason is not_recorded when no usage record exists yet (records are written about once a minute, and a create that never reached a vendor has none), or the reason the price table gives, such as a GPU type or a shape it has no price for. A create the vendor refused before it made a sandbox has a record that costs 0.

Errors

400
Bad Request Error
401
Unauthorized Error
402
Payment Required Error
403
Forbidden Error
404
Not Found Error
409
Conflict Error
413
Content Too Large Error
422
Unprocessable Entity Error
429
Too Many Requests Error
500
Internal Server Error