{
  "openapi": "3.0.1",
  "info": {
    "title": "Python & JS Code Runner – Sandbox for AI Agents & Workflows",
    "description": "Run Python or JavaScript (Node.js) code with JSON input in a fresh process: timeout with process-group kill, stdout/stderr capture, structured result, exit code, duration, pip/npm packages, batch jobs and dataset rows. Built for AI agents (MCP), n8n, Make and Zapier. Pay per execution.",
    "version": "0.1",
    "x-build-id": "z6YzOc3HCeIhKzZgn"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/gazidev~code-runner-sandbox/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-gazidev-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/gazidev~code-runner-sandbox/runs": {
      "post": {
        "operationId": "runs-sync-gazidev-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/gazidev~code-runner-sandbox/run-sync": {
      "post": {
        "operationId": "run-sync-gazidev-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",
        "properties": {
          "language": {
            "title": "Language",
            "enum": [
              "python",
              "javascript"
            ],
            "type": "string",
            "description": "Language of the top-level <code>code</code>. Jobs can override it with their own <code>language</code>.",
            "default": "python"
          },
          "code": {
            "title": "Code",
            "type": "string",
            "description": "Code to run. The job input is available as the variable <code>input</code> (also as file <code>$INPUT_PATH</code> and env <code>INPUT_JSON</code>).<br><b>Python:</b> set a top-level <code>result</code> variable (top-level <code>await</code> works).<br><b>JavaScript:</b> the code is the body of an async function - <code>return</code> a value, or set <code>module.exports</code>. Use <code>require()</code>, not <code>import</code>.<br>Fallback for both: if nothing is returned, the last line of stdout is parsed as JSON."
          },
          "inputJson": {
            "title": "Input (JSON)",
            "type": "object",
            "description": "JSON value passed to the code as <code>input</code>. Used by the top-level code and by jobs without their own <code>input</code>.",
            "default": {}
          },
          "jobs": {
            "title": "Batch jobs",
            "type": "array",
            "description": "Optional batch: a list of jobs, each <code>{\"id\": \"...\", \"language\": \"python|javascript\", \"code\": \"...\", \"input\": {...}, \"timeoutSecs\": 30}</code>. Every field is optional: a job without <code>code</code> reuses the top-level code (same code, many inputs). When this list is not empty the top-level code is <b>not</b> run on its own. Max 1,000 jobs per run. One dataset row per job."
          },
          "timeoutSecs": {
            "title": "Timeout per job (seconds)",
            "minimum": 1,
            "maximum": 300,
            "type": "integer",
            "description": "Wall-clock limit for one job. On timeout the job's whole process group is killed and the row gets status <code>timeout</code>.",
            "default": 30
          },
          "concurrency": {
            "title": "Parallel jobs",
            "minimum": 1,
            "maximum": 16,
            "type": "integer",
            "description": "How many jobs run at the same time. Raise it for big batches of short jobs (and give the run more memory).",
            "default": 1
          },
          "outputMode": {
            "title": "Dataset output",
            "enum": [
              "jobs",
              "rows"
            ],
            "type": "string",
            "description": "<b>jobs</b>: one dataset row per job. <b>rows</b>: when the code returns a list, each element becomes its own dataset row (with <code>_jobId</code>); max 10,000 rows per job. Job details are always in the <code>OUTPUT</code> record.",
            "default": "jobs"
          },
          "pythonPackages": {
            "title": "pip packages",
            "type": "array",
            "description": "Installed with pip once per run before the jobs start, e.g. <code>requests</code>, <code>pandas==2.2.3</code>. Max 30 packages in total, 1.5 GB, install timeout below. Adds 10-60 s to the run.",
            "items": {
              "type": "string"
            }
          },
          "npmPackages": {
            "title": "npm packages",
            "type": "array",
            "description": "Installed with npm once per run, e.g. <code>lodash</code>, <code>dayjs@1</code>. Load them with <code>require('lodash')</code>.",
            "items": {
              "type": "string"
            }
          },
          "packageInstallTimeoutSecs": {
            "title": "Package install timeout (seconds)",
            "minimum": 30,
            "maximum": 600,
            "type": "integer",
            "description": "If pip/npm install fails or takes longer, no job runs, nothing is charged and the run fails with the installer log.",
            "default": 180
          },
          "envVars": {
            "title": "Environment variables",
            "type": "object",
            "description": "Extra environment variables for the code, e.g. <code>{\"MODE\": \"test\"}</code>. Not stored as secrets - do not put passwords here."
          },
          "exposeApifyToken": {
            "title": "Give the code my APIFY_TOKEN",
            "type": "boolean",
            "description": "Off by default: the code's environment gets no APIFY_TOKEN and no other *TOKEN/*SECRET/*PASSWORD variables. Turn on only if your code must call the Apify API (e.g. to read a dataset or start another Actor).",
            "default": false
          },
          "saveOutputFiles": {
            "title": "Save files from ./output",
            "type": "boolean",
            "description": "Files the code writes into <code>./output/</code> (path also in env <code>OUTPUT_DIR</code>) are saved to the run's key-value store and linked in the row (<code>files[].url</code>). Max 20 files of 20 MB per job.",
            "default": true
          },
          "maxOutputKb": {
            "title": "Max stdout / stderr per job (KB)",
            "minimum": 1,
            "maximum": 4096,
            "type": "integer",
            "description": "Longer output is cut (flag <code>stdoutTruncated</code>). The returned result can be up to 5 MB.",
            "default": 256
          },
          "includeCodeInOutput": {
            "title": "Copy code & input into each row",
            "type": "boolean",
            "description": "Useful for audit logs of AI-generated code.",
            "default": false
          },
          "failRunOnError": {
            "title": "Fail the run if any job fails",
            "type": "boolean",
            "description": "Off: the run succeeds and each failed job is a row with <code>status</code> error/timeout (best for agents and loops). On: the run ends as FAILED when any job did not succeed (useful in n8n/Make/Zapier to branch on failure).",
            "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
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}