{
  "openapi": "3.0.1",
  "info": {
    "title": "Code Runner — Run Python & JavaScript with Input Data",
    "description": "Run Python 3.12 or JavaScript (Node 22) code in a sandboxed run: pass JSON input or dataset rows, install pip/npm packages, get stdout, stderr, exit code and returned rows. For data pipelines and AI agents (MCP). $0.0003 per execution plus run time.",
    "version": "0.1",
    "x-build-id": "zHuMDmxKZgDOEFem6"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/actor-forge~code-runner-sandbox/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-actor-forge-code-runner-sandbox",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/acts/actor-forge~code-runner-sandbox/runs": {
      "post": {
        "operationId": "runs-sync-actor-forge-code-runner-sandbox",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor and returns information about the initiated run in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/runsResponseSchema"
                }
              }
            }
          }
        }
      }
    },
    "/acts/actor-forge~code-runner-sandbox/run-sync": {
      "post": {
        "operationId": "run-sync-actor-forge-code-runner-sandbox",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "inputSchema": {
        "type": "object",
        "required": [
          "code"
        ],
        "properties": {
          "language": {
            "title": "Language",
            "enum": [
              "python",
              "javascript"
            ],
            "type": "string",
            "description": "Language of the code: \"python\" (Python 3.12) or \"javascript\" (Node.js 22). Aliases py, python3, js, node are accepted via the API.",
            "default": "python"
          },
          "code": {
            "title": "Code",
            "type": "string",
            "description": "The code to run (up to 1 MB). In scope: `input` (the Input JSON below, also sent on stdin), `rows` (list of rows loaded from the dataset, empty if none) and `push(row)` (adds a row to the output dataset). Return the result with a top-level `return` (Python and JavaScript); in Python a final bare expression or a variable named `result` also works. A returned list/array becomes dataset rows (one per item); any other value is saved in the `result` field. print()/console.log() go to `stdout`. JavaScript runs as the body of an async function: top-level `await` works, use `require()` or `await import()` for modules."
          },
          "input": {
            "title": "Input JSON",
            "type": "object",
            "description": "Any JSON object passed to the code as the variable `input` (also written to stdin as JSON). Use it for parameters, API responses or small data sets."
          },
          "datasetId": {
            "title": "Input dataset",
            "type": "string",
            "description": "Optional Apify dataset (ID or name) whose items are loaded into the variable `rows`, e.g. the output of a scraper to transform, filter or enrich. Picking it here gives this run read access to that dataset only."
          },
          "maxInputRows": {
            "title": "Max input rows",
            "minimum": 1,
            "maximum": 100000,
            "type": "integer",
            "description": "Maximum number of dataset items loaded into `rows` (first N items).",
            "default": 10000
          },
          "packages": {
            "title": "Packages to install",
            "type": "array",
            "description": "Optional pip packages (Python) or npm packages (JavaScript) installed before the code runs, e.g. \"pandas\", \"requests==2.32.3\", \"lodash\", \"dayjs@1.11.13\". Registry names with an optional version only (no URLs or options), at most 15. Installation is limited to 180 seconds and counts as run time. The standard library (json, csv, re, datetime, math, statistics, urllib; Node fetch, fs, crypto) needs no install.",
            "items": {
              "type": "string"
            }
          },
          "timeoutSecs": {
            "title": "Timeout (seconds)",
            "minimum": 1,
            "maximum": 900,
            "type": "integer",
            "description": "Hard limit for the code's run time. The process and anything it started are killed when it is reached and status \"timeout\" is returned. It is lowered automatically to fit the run's maximum charge and the run timeout.",
            "default": 60
          },
          "outputMode": {
            "title": "Output mode",
            "enum": [
              "auto",
              "result-row"
            ],
            "type": "string",
            "description": "auto: a returned list (and anything passed to push()) is saved as dataset rows, and stdout/stderr/exit code go to the OUTPUT record; if nothing is returned as a list, the dataset gets one result row. result-row: the dataset always gets exactly one row with status, stdout, stderr, exit code, duration and the returned value in `result` (best for AI agents and MCP clients).",
            "default": "auto"
          },
          "maxOutputRows": {
            "title": "Max output rows",
            "minimum": 1,
            "maximum": 500000,
            "type": "integer",
            "description": "Maximum number of rows saved to the dataset; extra rows are dropped (and not charged).",
            "default": 10000
          },
          "failOnError": {
            "title": "Fail the run when the code fails",
            "type": "boolean",
            "description": "If on, the Apify run ends as FAILED when the code raises an error, exits non-zero or times out (useful to stop a pipeline). If off, the run succeeds and the row has status \"error\" or \"timeout\" with the error and stderr.",
            "default": false
          }
        }
      },
      "runsResponseSchema": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "actId": {
                "type": "string"
              },
              "userId": {
                "type": "string"
              },
              "startedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "finishedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "status": {
                "type": "string",
                "example": "READY"
              },
              "meta": {
                "type": "object",
                "properties": {
                  "origin": {
                    "type": "string",
                    "example": "API"
                  },
                  "userAgent": {
                    "type": "string"
                  }
                }
              },
              "stats": {
                "type": "object",
                "properties": {
                  "inputBodyLen": {
                    "type": "integer",
                    "example": 2000
                  },
                  "rebootCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "restartCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "resurrectCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "computeUnits": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "options": {
                "type": "object",
                "properties": {
                  "build": {
                    "type": "string",
                    "example": "latest"
                  },
                  "timeoutSecs": {
                    "type": "integer",
                    "example": 300
                  },
                  "memoryMbytes": {
                    "type": "integer",
                    "example": 1024
                  },
                  "diskMbytes": {
                    "type": "integer",
                    "example": 2048
                  }
                }
              },
              "buildId": {
                "type": "string"
              },
              "defaultKeyValueStoreId": {
                "type": "string"
              },
              "defaultDatasetId": {
                "type": "string"
              },
              "defaultRequestQueueId": {
                "type": "string"
              },
              "buildNumber": {
                "type": "string",
                "example": "1.0.0"
              },
              "containerUrl": {
                "type": "string"
              },
              "usage": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "integer",
                    "example": 1
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_UNBLOCKER_UNITS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "usageTotalUsd": {
                "type": "number",
                "example": 0.00005
              },
              "usageUsd": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "number",
                    "example": 0.00005
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_UNBLOCKER_UNITS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}