Python & JS Code Runner – Sandbox for AI Agents & Workflows
Pricing
from $0.80 / 1,000 code executions
Python & JS Code Runner – Sandbox for AI Agents & Workflows
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.
Pricing
from $0.80 / 1,000 code executions
Rating
0.0
(0)
Developer
Cemal Atakli
Maintained by CommunityActor stats
0
Bookmarked
2
Total users
1
Monthly active users
a day ago
Last modified
Categories
Share
Python & JavaScript Code Runner: a code sandbox for AI agents, n8n and Make
Run Python 3.13 or JavaScript (Node.js 22) code with a JSON input and get a structured result back: the return value, stdout, stderr, exit code and duration. Every job runs in a fresh process with a hard timeout. You can install pip / npm packages at runtime, run batches of jobs (the same code over many inputs, or many different snippets), and turn a returned list into dataset rows.
It is made for AI agents (Apify MCP), n8n / Make / Zapier workflows and API users who need to "just run this snippet" without servers or a Docker setup.
Why this code runner
- Reliable by design. A failing or hanging user script never fails the run. Each job ends with a clear
status(ok,error,timeout), the error type and message, and a trimmed traceback. - A hard timeout that really stops the code. When a job times out, its whole process group is killed, including child processes it started.
- Structured result, not only text. Python sets
result = .... JavaScript usesreturn .... If the code returns nothing, the last stdout line is parsed as JSON. - Batch jobs. Up to 1,000 jobs per run, with optional parallel execution (
concurrency). - Packages.
pythonPackages: ["pandas"]andnpmPackages: ["lodash"]are installed once per run and shared by all jobs. - Files. Anything the code writes to
./output/is saved to the run's key-value store, and the row links to it. - Safe defaults. Your
APIFY_TOKENand other*TOKEN/*SECRET/*PASSWORDvariables are removed from the code's environment unless you opt in. stdout and stderr are capped at 256 KB per job by default, and the result at 5 MB. - Cheap. You pay $0.0008 per execution. There is no monthly fee and no start-up fee beyond Apify's tiny Actor start event.
Code conventions
| Python | JavaScript (Node.js) | |
|---|---|---|
| Input | variable input (dict / list / value) | variable input |
| Return data | set top-level result = {...} | return {...}. You can also use module.exports = value, module.exports = async (input) => ... or exports.main = async (input) => ... |
| Async | top-level await works | top-level await works (the code runs inside an async function) |
| Packages | import pandas after adding "pandas" to pip packages | require('lodash') after adding "lodash" to npm packages. Use require, not import |
| Fallback | last stdout line, if it is valid JSON | last stdout line, if it is valid JSON |
The code can also use the file $INPUT_PATH, the env variable INPUT_JSON (for inputs up to 64 KB) and $OUTPUT_DIR (= ./output).
Input example
{"language": "python","code": "import statistics\nresult = {'mean': statistics.mean(input['numbers'])}","inputJson": {"numbers": [4, 8, 15, 16, 23, 42]},"timeoutSecs": 30}
Batch: the same code over many inputs, plus one JavaScript job with its own code:
{"language": "python","code": "result = input['n'] ** 2","jobs": [{"id": "a", "input": {"n": 3}},{"id": "b", "input": {"n": 4}},{"id": "js", "language": "javascript", "code": "return input.text.toUpperCase();", "input": {"text": "hi"}}],"concurrency": 4}
Output example (one dataset row per job)
{"jobId": "python-stats","language": "python","status": "ok","ok": true,"exitCode": 0,"durationMs": 50,"result": {"count": 6, "sum": 108, "mean": 18, "sorted": [4, 8, 15, 16, 23, 42]},"resultSource": "result-variable","stdout": "Got 6 numbers\n","stderr": "","error": null,"files": [],"charged": true}
A failed job looks like this: "status": "error", "exitCode": 1, "error": {"type": "ValueError", "message": "..."}, and stderr holds the traceback of your code only. A timeout gives "status": "timeout".
The OUTPUT record in the key-value store holds the run summary. For a single job it also holds that job's result, which is handy for API calls.
With Dataset output = rows, a returned list such as [{"name": "A"}, {"name": "B"}] becomes dataset rows, each with a _jobId field. This lets your code act as a small scraper or data generator in a pipeline.
Use with AI agents (Apify MCP)
Add the Actor to your MCP client through the Apify MCP server (https://mcp.apify.com?tools=gazidev/code-runner-sandbox). The agent can then call it as a tool:
- send
language,codeandinputJson, then readresult,stdout,stderranderrorfrom the dataset row - the agent can retry after an error, because each failure says what went wrong (
error.type,error.message, traceback) - set
timeoutSecslow (5 to 30 s) for agent loops, and keepfailRunOnErroroff so the agent always gets the row
Typical agent uses: exact math and statistics, date arithmetic, parsing and transforming JSON or CSV, checking a regex, testing a generated function against cases, and small data jobs with pandas.
Use in n8n, Make and Zapier
Use the "Run Actor and get dataset items" action. To branch on failures, turn on Fail the run if any job fails. Otherwise, check ok in each row.
Pricing
| Event | Price | When |
|---|---|---|
| Execution | $0.0008 | per finished job, including the first 5 s of run time |
| Extra run time | $0.004 | per started 10 s beyond the first 5 s, per started GB of run memory (default memory is 512 MB, which counts as 1 GB) |
| Packages installed | $0.005 | once per run, only when pip/npm packages were installed successfully |
A finished job is charged even when your code raises an error, exits non-zero or times out, because the code did run. Not charged: invalid input, package install failures (no job runs), jobs that were never started, and platform errors.
Examples: 1,000 short jobs cost about $0.80. A single 2-second snippet costs $0.0008 plus the Actor start event.
Max cost per run is respected. Jobs start only while your budget covers them. A long job's timeout is shortened to fit the budget, and the rest of the jobs are listed as not-run.
| Actor | Price per execution (FREE tier) | Notes |
|---|---|---|
| This Actor | $0.0008 + time beyond 5 s | Python and JS, batch, pip/npm, rows output |
| parsebird/code-runner-sandbox | $0.00099 | one execution per run |
| automation-lab/ai-code-runner-sandbox | $0.0010 + $0.005 start | |
| rixin/execute-javascript-code | $0.0009 per second | JavaScript only |
| apify/ai-code-sandbox | free (you pay the compute) | interactive sandbox, different use case |
(Store prices checked on 2026-10-24.)
FAQ
Is it secure? Every job runs in a separate process inside your own Apify run container. Apify isolates that container from other users. Secrets are removed from the job environment by default. There is no extra seccomp or network jail inside the container, so the code can reach the internet. Treat untrusted code the way you would in any container.
Can my code call the Apify API? Yes. Turn on Give the code my APIFY_TOKEN. The Python apify / apify-client packages are already installed.
Which versions are installed? Python 3.13 and Node.js 22 with npm. Python's standard library is available with no installs.
What happens if the job prints a lot? stdout and stderr are cut at maxOutputKb (default 256 KB, max 4 MB), and stdoutTruncated is set. Return big data as a list (rows mode) or as files in ./output/.
What about memory? Jobs share the run memory: 512 MB by default, and you can set it up to 8 GB in the run options. Raise it for pandas and big inputs, or when you use concurrency > 1.
Are results returned in order? With concurrency 1 the rows are in job order. With parallel jobs they are in the order the jobs finish. Use jobId to match them.