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 > API Keys. Signed-in members and the CostGraph MCP server can also call these endpoints.
X-API-Key header to https://api.costgraph.ai. Responses
wrap their payload in data.
How a provider is chosen
When you start a sandbox without naming a provider, CostGraph orders your connected providers with your routing policy. It tries them in that order until one starts the sandbox. The following rules apply:- Your first connected provider is the baseline. Providers are ordered by when you connected them, oldest first.
- While AutoPilot for sandboxes is off, CostGraph tries your providers in that order.
- If a provider has several connections, CostGraph uses the oldest working one.
providerlimits the start to one provider.- A budget set to stop sandboxes removes the providers it covers while it is over.
quota, capacity, auth, timeout, or other, and lowers
the provider’s success rate. When a provider refuses CostGraph’s key, later
sandboxes skip it until you reconnect it on Integrations.
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 in Ready timeout, under
AutoPilot > Sandboxes > Settings. 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.
CostGraph passes your tags to the provider as labels. The
run tag is the
sandbox’s run key. Without one, CostGraph generates a key. Refer to
Group cost by run. Keys that
start with costgraph.ai/ are reserved, and CostGraph drops them from your tags.
The response describes the sandbox.
provider and sandbox_id in the sandbox’s paths. price_per_hour is the
list price in USD, or null without a price. routed_from names the provider
tried first, when the sandbox started on another provider.
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. Every call records the time as the sandbox’s last use.
Files can be up to 4 MiB. The list does not include sandboxes started by
workflows, CI jobs, or your own code.
Run a command
Send the command to the sandbox’sexec path.
command is required, up to 64 KiB. env takes up to 100 environment
variables. timeout_ms can be up to 55,000 milliseconds, and the default wait
is 30 seconds. The response has exit_code, stdout, and stderr. Each stream
holds up to 256 KiB, and truncated is true when CostGraph cut either one. For a
longer task, send background: true, write the output to a file, and read the
file when the task ends.
Connect to sandboxes from TypeScript
costgraphConnections() in @costgraph/computesdk is a ComputeSDK provider
that calls this API.
costgraphConnections() accepts the following options.
Sandboxes support
runCommand, getInfo, destroy, filesystem.readFile, and
filesystem.writeFile. Snapshots and volumes are not available. timeout on
create() becomes lifecycle.timeout_ms. Read a generated run key 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 afterlifecycle.timeout_ms or its own timeout.
When a call finds that the provider ended the sandbox, CostGraph records it as
stopped and the call answers 404.
A running sandbox keeps billing until it stops. When its cost since its last
use passes the insight cost floor, CostGraph opens a
forgotten sandbox insight.