Requirements
- At least one sandbox provider connected on Integrations > Sandbox, as described in Connect. Supported sandbox providers lists the providers.
- A CostGraph API key with the
sandbox:runscope. Create it in Settings > Personal API Keys. Members signed in to CostGraph and the CostGraph MCP server can also call these endpoints.
data wrapper work as described in
Requirements for the routing
API.
How a provider is chosen
When you start a sandbox without naming a provider, CostGraph orders your connected providers for the sandbox’s size, as the routing API does. It then tries them in that order until one starts the sandbox.- Your first connected provider is the baseline. Providers are listed in the order you connected them, oldest first.
- Your routing policy sets the order. The policies are described in
Policies. Send
policyto use another policy for one sandbox. - While AutoPilot for sandboxes is off, the order is yours. CostGraph tries your providers in the order you connected them.
- One connection serves each provider. If you connected a provider more than once, CostGraph uses the oldest connection that works.
providerlimits the start to one provider. CostGraph then tries no other provider.
When a start fails
CostGraph tries the next provider when a provider refuses to create the sandbox, or when the sandbox is not ready within the readiness limit. Each failed start is recorded with one of the following classes.
Failed starts lower the provider’s success rate, which AutoPilot uses to rank
it for later sandboxes. Refer to
Expected cost and start time.
When a provider refuses CostGraph’s key, the connection shows
<Provider> refused CostGraph's key; reconnect it on Integrations.
Later sandboxes skip that provider until you connect it again with a key that
works.
If no provider starts the sandbox, the request answers 502.
Readiness limit
A provider has 30 seconds to make a new sandbox ready. After that, CostGraph counts the start as failed with classtimeout and tries the next provider.
Admins can set the limit from 5 to 600 seconds with ready_timeout_seconds on
the settings endpoint.
The limit also applies to workflow sandboxes that
AutoPilot chooses.
Start a sandbox
Send the size and your tags. Allow the request a few minutes, because CostGraph can try more than one provider.
Without a size, each provider starts its own default size, and CostGraph prices
the sandbox at that size.
CostGraph passes your tags to the provider as labels on the sandbox. The
run
tag is the sandbox’s run key. Use it to group the sandboxes of one agent run.
CostGraph also sets it on the sandbox as the provider label costgraph.ai/run.
Keys that start with costgraph.ai/ are reserved for CostGraph, and CostGraph
drops them from your tags.
The response describes the sandbox.
Use a sandbox
Each sandbox has its own path,/api/v1/tenant/sandboxes/{provider}/{sandbox_id}.
These calls reach only sandboxes started through this API or the CostGraph MCP
tools. A sandbox stays on the provider connection that started it.
Every call on a sandbox records the time as its last use.
List running sandboxes
GET /api/v1/tenant/sandboxes lists your running sandboxes, newest first. Each
sandbox has the following fields.
Sandboxes started by workflows, CI jobs, or your own code are not listed.
Read a sandbox
GET /api/v1/tenant/sandboxes/{provider}/{sandbox_id} checks with the provider
that the sandbox still runs. It returns the fields of the list with
running: true.
Run a command
POST /api/v1/tenant/sandboxes/{provider}/{sandbox_id}/exec runs a shell
command in the sandbox.
The response has
exit_code, stdout, and stderr. Each output stream holds
at most 256 KiB, and truncated is true when CostGraph cut either one. For
a longer task, start it with background: true, write its output to a file, and
read the file when the task ends.
Read and write files
GET /api/v1/tenant/sandboxes/{provider}/{sandbox_id}/files?path=<path> returns
the file at path as content_base64.
PUT on the same path with the body {"content_base64": "<base64>"} writes
the file and replaces any file at that path. The call answers 204.
Files can be up to 4 MiB.
End a sandbox
DELETE /api/v1/tenant/sandboxes/{provider}/{sandbox_id} ends the sandbox. The
call answers 204.
Use it from TypeScript
costgraphConnections() in @costgraph/computesdk is a ComputeSDK provider
that calls this API. Pass an API key with the sandbox:run scope as apiKey,
or an OAuth access token that can use the CostGraph MCP tools as
accessToken.
runCommand, getInfo, destroy, and the file methods
filesystem.readFile and filesystem.writeFile. Snapshots, volumes, and other
instance methods are not available. instances.list() and getById
reach the running sandboxes started through this API or the CostGraph MCP
tools. timeout on create() becomes lifecycle.timeout_ms.
costgraphConnections() accepts the following options.
Without a
run tag, the package generates a run key for each sandbox. Read it
with runKey(sandboxId) on the provider.
How sandboxes stop
CostGraph does not end a sandbox on its own. A sandbox stops when you end it, or when the provider ends it at the end oflifecycle.timeout_ms or its own
timeout. When a call finds that the provider has ended the sandbox, CostGraph
records it as stopped and the call answers 404.
Each stopped sandbox has one of the following stop reasons on the
runs endpoint.
A running sandbox keeps billing until it stops. When a sandbox’s cost since its
last use reaches the insight cost floor,
CostGraph opens a forgotten sandbox insight.