Code Runner — Run Python & JavaScript with Input Data avatar

Code Runner — Run Python & JavaScript with Input Data

Pricing

from $0.30 / 1,000 code executeds

Go to Apify Store
Code Runner — Run Python & JavaScript with Input Data

Code Runner — Run Python & JavaScript with Input Data

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.

Pricing

from $0.30 / 1,000 code executeds

Rating

0.0

(0)

Developer

ActorForge

ActorForge

Maintained by Community

Actor stats

0

Bookmarked

7

Total users

6

Monthly active users

7 days ago

Last modified

Features

Limited permissions

Share

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.

Run a Python or JavaScript snippet on Apify and get its output back as data: no server, no Lambda, no notebook. Paste code, pick Python 3.12 or JavaScript (Node.js 22), pass parameters as Input JSON and, optionally, an Apify dataset to process. Your code sees them as the variables input and rows, can return a list that becomes dataset rows (one per item), and can install pip or npm packages (pandas, requests, lodash, dayjs, cheerio…) at runtime. Every run returns stdout, stderr, exit code, duration and the returned value, so you always see what happened.

Built for pipelines and AI agents. Use it as the "code step" between scrapers: reshape, filter, score, dedupe or enrich a scraper's dataset, compute stats, call an API and reformat the response, then feed the rows to Make, n8n, Zapier, Clay or the next actor. AI agents and MCP clients (Claude, ChatGPT, Cursor and other assistants connected to Apify) can call it as a code-execution tool: set outputMode to result-row and every call returns exactly one row with status, stdout, stderr, exitCode, durationMs and result. Errors never crash the run: you get status error with the message, the line number and the traceback (or turn on failOnError to fail the run and stop a pipeline).

Safe by design. Each execution runs in your own Apify run, in a fresh temporary folder that is deleted afterwards. A hard timeout kills the code and everything it started, output is capped, and no Apify token or other secret is placed in the code's environment. Packages are restricted to registry names with an optional version (no URLs, git refs or installer options).

How to use it

Python (top-level return, a final bare expression, or a variable named result all work):

import statistics
prices = [r["price"] for r in rows if r.get("price")]
return [{"count": len(prices), "median": statistics.median(prices), "max": max(prices)}]

JavaScript (runs as the body of an async function, so top-level await and return work; use require() or await import()):

const res = await fetch(input.apiUrl, { headers: { accept: 'application/json' } });
const data = await res.json();
return data.items.map((i) => ({ id: i.id, title: i.title.trim() }));
  • input: the Input JSON (also sent on stdin). rows: items of the Input dataset (up to maxInputRows). push(row): add a row to the output while the code runs.
  • Returned list → one dataset row per item (non-objects become {"value": …}); any other value → the result field of the result row. The full execution record (stdout, stderr, exit code, billing) is always in the run's OUTPUT record.
  • From the API / an agent: call actor actor-forge~code-runner-sandbox with {"language": "python", "code": "return 6*7", "outputMode": "result-row"} and read the dataset items of the run.

Priced for small, frequent executions: $0.0003 per execution including the first 2 GB-seconds of run time (about 8 seconds at the default 256 MB) and the first 100 rows, then $0.0001 per extra GB-second and $0.01 per 1,000 extra rows. Invalid input, failed package installs and dataset errors are free.

What data does it return?

Every run outputs clean, schema-validated rows like these:

namelengthupper
Ada3ADA
Grace5GRACE
Linus5LINUS

How much does it cost?

Transparent pay-per-event pricing — you only pay for what you get, and the actor always respects your run budget: set a maximum total charge and it stops cleanly at the cap instead of overrunning.

EventPriceChargedWorked example
code-executed$0.0003per execution of your code (includes the first 2 GB-seconds of run time and the first 100 output rows; invalid input, failed package installs and dataset errors are free)The prefill example (3 rows, about 3 seconds at 256 MB) = $0.0003 (measured)
compute-second$0.0001per extra GB-second of run time (seconds × memory in GB) beyond the 2 includedA 60-second job at 256 MB = 15 GB-s − 2 included = 13 × $0.0001 = $0.0013, plus $0.0003 = $0.0016
row-output$0.00001per dataset row beyond the first 100 of a runTransform a 10,000-row dataset in 20 s at 512 MB = $0.0003 + 8 × $0.0001 + 9,900 × $0.00001 ≈ $0.10
apify-actor-start$0.00005per run per GB of memory (platform start fee)One run at 256 MB = $0.00005

Input options

FieldTypeRequiredDefaultDescription
languagestringno"python"Language of the code: "python" (Python 3.12) or "javascript" (Node.js 22). Aliases py, python3, js, node are accepted via the API.
codestringyes—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.
inputobjectno—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.
datasetIdstringno—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.
maxInputRowsintegerno10000Maximum number of dataset items loaded into rows (first N items).
packagesarrayno—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.
timeoutSecsintegerno60Hard 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.
outputModestringno"auto"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).
maxOutputRowsintegerno10000Maximum number of rows saved to the dataset; extra rows are dropped (and not charged).
failOnErrorbooleannofalseIf 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.

Limits & honest notes

  • Runtimes: Python 3.12 (Alpine Linux, musl) and Node.js 22. Most popular pip packages ship compatible wheels (pandas, numpy, requests, beautifulsoup4, pydantic…); packages that must compile C code may fail to install. Installation is limited to 180 seconds and its time counts as run time.
  • The default memory is 256 MB, which also means a small CPU share. For pandas/numpy work or large datasets raise the run memory (up to 4 GB); run-time charges scale with memory (GB-seconds).
  • Timeout: 1–900 seconds per execution (default 60). It is lowered automatically so the run stays within your maximum charge and the run timeout. On timeout the code and its child processes are killed and status is "timeout".
  • stdout and stderr are kept up to 100,000 characters each in the row (1 MB per stream is read; the rest is discarded). A returned value is limited to 200 MB, a single row to 8 MB, and the result field to 2 MB of JSON.
  • Input dataset: up to 100,000 items are loaded into memory as rows. The run can read only the dataset you pick (or pass by ID in the API input).
  • The code has normal outbound internet access from the run (for APIs and downloads). It runs as your own Apify run, so anything it does uses your account; do not paste untrusted code you would not run yourself.
  • Files written by the code are not kept after the run; return the data (or rows) you need. Python's input() is replaced by the input variable — read stdin with sys.stdin instead.
  • Each execution starts a fresh environment: nothing is cached between runs, so packages are reinstalled each time.

Changelog

  • 2026-11-12 — Initial release: Python 3.12 and Node.js 22, Input JSON and dataset rows, pip/npm packages, returned list → dataset rows, push(), result-row mode for AI agents, hard timeouts and output caps.

Built and maintained by ActorForge. Reliability first: every actor in the portfolio is monitored by an automated nightly self-test, and breakages are typically fixed the same day.