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}untilstatusisrunningorfailed. - Add
?wait=trueto hold this request until then, for up towait_timeout_seconds. If the wait ends first you still get 202 withcreating, and the create continues. - Set
webhook_urland wait for thesandbox.runningevent.
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
imageandimage_idis required. - Unknown fields return 400, and so does a known field set to
null. The removed fieldsmodel_access,sandbox_access, andprovider_optionsreturn 400. To let code in the sandbox call Meadow, mint a narrow key withPOST /v1/keysand pass it inenv. provider.optionsis 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.resourcesare honoured on both vendors, but the units differ and Meadow does not convert them:cpucounts virtual CPUs on Daytona and physical cores on Modal. On Modalcpuandmemory_mbare hard limits unless you sendprovider.options.modal.burst: true. A size or GPU type a vendor cannot serve skips that vendor with anunsupportedattempt that carries the reason. Seeresources.- The response does not echo
image,image_id,env,timeout_seconds,idle_timeout_seconds, orwebhook_url. Keep them on your side if you need them later.networkis returned.
Scope: sandboxes.
Authentication
A Meadow API key, sent as Authorization: Bearer mdw_.... The header
x-api-key: mdw_... is accepted in its place.
Headers
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
When true, hold the request until the sandbox is running or failed, or
until wait_timeout_seconds passes.
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
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.
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.
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.
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).
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.
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}.
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.
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.
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.
Your own key and value pairs, returned with the sandbox and usable as a filter on GET /v1/sandboxes. Keys must not be empty.
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
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.
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.
Response
Accepted. Without wait the sandbox is creating. With wait=true it is
usually running or failed.
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, bytimeout_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. Seefailure_reason.
Why the sandbox is failed. Null otherwise.
all_providers_failed: every provider in the route failed, for mixed reasons. Readattempts.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.
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.
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.
When the sandbox became running. Null before that.
When timeout_seconds ends the sandbox: started_at plus the timeout. Null until it is running.
When the sandbox became terminated. Null otherwise.
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_reasonsays why:grant_unconfirmed(the vendor has not yet confirmed the size, so the size asked for is priced),spot_unconfirmed, ormeadow_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), orvendor_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, andcostis null. Unknown never means free.cost_reasonisnot_recordedwhen 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.