---
title: "Run a script"
method: POST
path: "/script_runs"
tags: ["ScriptRuns"]
---

# Run a script

`POST /script_runs`

## Request

- Base URL: `https://api.crevio.co/v1`
- URL: `https://api.crevio.co/v1/script_runs`
- Auth: API key in header `Authorization`

Runs JavaScript on the account's computer with bun, with no agent turn, as the key's owner (account admins only; team keys cannot). `tools.<namespace>.<function>(args)` calls the Crevio API and connected integrations, and the script's last expression is its `result`. `args` reach the script as the global `args` (and `process.argv`). Files written into the directory named by the global `outputDir` (20 at most, 50 MB each) come back as `artifacts`. A call that needs approval does not run: it resolves to `{pending: true, draft_id, approval}`, the script carries on, and the run lists it in `approvals` and `pending_approval_ids`. Approving it (POST /approvals/{id}/approve) runs that one frozen call, never the script again. `200` when it finished within `wait_seconds`, `202` otherwise: poll GET /script_runs/{id}. At most 4 runs in flight per user and 8 per account (`429`). Needs the `scripts` scope.

## Headers

- `Idempotency-Key` string

## Request body

- object
  - `code` string, required: The JavaScript to run.
  - `args` string[]: Values the script reads from the global `args`.
  - `timeout_seconds` integer: How long the script may run.
  - `wait_seconds` integer: Hold the response until the script finishes, up to this many seconds.

## Response `200`

The script finished within wait_seconds

- ScriptRun
  - `object` string, required
  - `id` string, required
  - `status` 'queued' | 'in_progress' | 'completed' | 'failed' | 'cancelled' | 'timed_out', required
  - `result` unknown, required
  - `result_truncated` boolean, required: The value was too large to return, so `result` holds the start of its JSON text instead.
  - `output` string, nullable, required: What the script printed: its start and end when long, with the cut marked.
  - `error` string, nullable, required
  - `args` string[], required
  - `calls` object[], required: Every tool call the script made, in order: `{role, status, read_only, error_code, approval_id}`. A 202 call did not run and names its approval.
  - `approvals` Approval[], required: What the script's gated calls froze, as each stands now. Approving one runs that call, never the script again.
    - `object` 'approval', required
    - `id` string, required
    - `approval_id` string, required
    - `status` 'draft' | 'pending_approval' | 'approved' | 'executed' | 'failed' | 'denied', required: `pending_approval` waits for a person. It ends `executed` (see `result`), `failed` (see `error`) or `denied` (see `reason`).
    - `kind` 'pipedream' | 'composio' | 'rest' | 'mcp' | 'native' | 'saved_tool' | 'site' | 'vault' | 'elicitation', required
    - `action_type` string, nullable, required
    - `title` string, nullable, required
    - `details` object[], required: What runs, as `{label, value}` pairs: recipients, subject, amounts and the other arguments a person checks.
    - `request` object, nullable, required: An API call's frozen request, `{http_method, path, params}`, with secrets masked. Null for other kinds.
    - `app_slug` string, nullable, required
    - `tool_name` string, nullable, required
    - `result` object, nullable, required
    - `error` string, nullable, required
    - `reason` string, nullable, required
    - `chat_id` string, nullable, required
    - `created_at` string, required
    - `resolved_at` string, nullable, required
  - `pending_approval_ids` string[], required: Approvals still waiting for a decision: POST /approvals/{id}/approve or /deny.
  - `artifacts` Artifact[], required: Files the script wrote to `outputDir`.
    - `object` string, required
    - `id` string, required
    - `filename` string, required
    - `content_type` string, nullable, required
    - `size` integer, required
  - `timeout_seconds` integer, required
  - `started_at` string, nullable, required
  - `completed_at` string, nullable, required
  - `created_at` string, date-time, required

## Other responses

- `202`: The script is still queued or running
- `400`: Bad request
- `401`: Authentication required
- `403`: Forbidden
- `422`: Validation error
- `429`: Rate limit exceeded — 600 requests per minute per owner on the free tier: every API key and OAuth token one person holds on an account shares one budget, and the account's team keys share another. Retry after the number of seconds in `Retry-After`.
- `500`: Internal server error

## Changes

- **2026-12-05** `ccbd8fcbd6d7`: 4 info
  - added the required property `approvals/items/details` to the response with the `200` status
  - added the required property `approvals/items/details` to the response with the `202` status
  - added the required property `approvals/items/request` to the response with the `200` status
  - added the required property `approvals/items/request` to the response with the `202` status
- **2026-12-04** `6be3ac8d9549`: 2 warning
  - added the new `site` enum value to the `approvals/items/kind` response property for the response status `200`
  - added the new `site` enum value to the `approvals/items/kind` response property for the response status `202`
- **2026-11-15** `56c22ab9b282`: 6 warning, 2 info
  - added the new `idempotency_error` enum value to the `error/type` response property for the response status `400`
  - added the new `idempotency_error` enum value to the `error/type` response property for the response status `401`
  - added the new `idempotency_error` enum value to the `error/type` response property for the response status `403`
  - added the new `idempotency_error` enum value to the `error/type` response property for the response status `422`
  - …4 more
- …earlier changes not shown

[Operation history](https://skmtc.dev/crevio/apis/crevio-api-v1/changes/script_runs/post.md)

---

[API](https://skmtc.dev/crevio/apis/crevio-api-v1.md) - [All operations](https://skmtc.dev/crevio/apis/crevio-api-v1/llms.txt) - [OpenAPI document](https://skmtc.dev/crevio/apis/crevio-api-v1/revisions/ccbd8fcbd6d7?raw)
