Start code run
POST /v1/organisations/{organisation_id}/spaces/{space_id}/files/{file_id}/runs
Runs a code file in a gVisor sandbox as the caller. Output streams from …/runs/{run_id}/events; outputs are saved as new file versions.
Authentication
Send an API key, or an access token from your organisation’s identity provider, in the Authorization header. How API keys work
Scope the API key needs: code_runs:write
Security schemes in the OpenAPI document: session_cookie (cookie __Host-ivy_session)bearer (bearer)api_key (bearer)
Parameters
-
organisation_idpathstringrequired -
space_idpathstringrequired -
file_idpathstringrequired
Request body
application/json StartRun required
-
client_run_idstringrequiredThe client's id for this run: repeating it returns the same run.
-
connectionsstring[]Connections declared with
direct_runs: truethe run may call through the gateway; a person's runs only, never a key's. -
egressstring[]Hosts of the space allow-list the run may reach; without them it has no network.
-
environmentstring|nullThe sandbox environment that runs the file; by default the first built-in environment whose run rules match it.
-
filesstring[]Files, folders (
Inbox/,Inbox/**with subfolders) and globs (Finance/*.csv) you can read, staged read-only under$IVY_IN/files/at their current clean versions. -
inputobject|nullA JSON value staged read-only as
$IVY_IN/input.json(workflows-design.md §5.2.1). -
input_file_idsstring[]Space files copied into the sandbox read-only, beside the code file.
-
messagesRunMessages[]Channels of the space you can read, staged as
$IVY_IN/messages/<channel>.json. -
output_folder_idstring|nullWhere new output files go; defaults to the code file's folder.
-
save_tostring|nullA folder path or id to save new output files in; the code file's folder by default.
-
tierComputeTier|null -
timeout_secondsinteger (int32)|null10 s up to the installation's maximum (15 min by default); shortened to what the remaining credits cover.
minimum 0 -
version_idstring|nullDefaults to the version currently served.
Responses
-
Queued; repeating
client_run_idreturns the same run -
unauthenticated -
usage_limit_reached,billing_restricted -
forbidden: editors and admins only;tier_not_available,invalid_origin -
No such file or version in this space;
environment_not_found -
run_in_progress,file_scanning;environment_not_ready: the environment is off -
inputs_too_large -
file_not_runnable: no rule of the environment (or of any built-in, when none is named) matches the file (details.patterns);validation_failed;sandbox_tier_unavailable: the installation doesn't offer that size (details.enabled_tiers) -
rate_limited: the API key's requests per minute are used up; retry afterRetry-Afterseconds -
sandbox_unavailable: no gVisor sandbox on this installation (details.reason); orunavailable: the database is briefly unavailable; retry afterRetry-Afterseconds
Error codes
Errors come back as an ErrorBody whose code is one of these.
- 401
unauthenticated - 402
usage_limit_reachedbilling_restricted - 403
forbiddentier_not_availableinvalid_origin - 404
environment_not_found - 409
run_in_progressfile_scanningenvironment_not_ready - 413
inputs_too_large - 422
file_not_runnablevalidation_failedsandbox_tier_unavailable - 429
rate_limited - 503
sandbox_unavailableunavailable
Examples
curl -X POST "$IVY_API_URL/v1/organisations/$ORGANISATION_ID/spaces/$SPACE_ID/files/$FILE_ID/runs" \
-H "Authorization: Bearer $IVY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"client_run_id":"client_run_123"}' import { client, startCodeRun } from "@spacivapp/ivy-sdk";
client.setConfig({
baseUrl: process.env.IVY_API_URL,
headers: { Authorization: `Bearer ${process.env.IVY_API_KEY}` },
});
const { data, error, response } = await startCodeRun({
path: { organisation_id: organisationId, space_id: spaceId, file_id: fileId },
body: {
client_run_id: "client_run_123"
},
}); {
"client_run_id": "client_run_123",
"connections": [
"string"
],
"egress": [
"string"
],
"environment": "string",
"files": [
"string"
],
"input": {},
"input_file_ids": [
"string"
],
"messages": [
{
"channel": "string",
"since": "string"
}
],
"output_folder_id": "output_folder_123",
"save_to": "string",
"tier": "string",
"timeout_seconds": 0,
"version_id": "version_123"
} {
"run_id": "run_123",
"timeout_seconds": 0
}