Code runtime
Pricing
Pay per usage
Code runtime
This Actor executes TypeScript/JavaScript that an AI agent submits through the Apify MCP Server's Code Mode, then returns whatever the script printed.
Pricing
Pay per usage
Rating
0.0
(0)
Developer
Apify
Maintained by CommunityActor stats
0
Bookmarked
3
Total users
2
Monthly active users
9 days ago
Last modified
Categories
Share
Code Runtime (experimental)
⚠️ Experimental infrastructure Actor. It powers Code Mode on mcp.apify.com and is normally invoked by the Apify MCP Server, not run by hand. Its behaviour and API may change without notice.
What it does
This Actor executes TypeScript/JavaScript that an AI agent submits through the Apify MCP Server's Code Mode, then returns whatever the script printed.
Code Mode exists so an agent can do many Apify operations in one go — search the Store, run an Actor, read its dataset, filter and aggregate the results — instead of sending every intermediate result back through the model and wasting tokens. This Actor is the sandbox that runs that script.
Enabling Code Mode on the MCP Server
Code Mode is opt-in. Add the Code Mode tools to the tools query parameter of
your mcp.apify.com connection URL:
https://mcp.apify.com/?tools=run-code,get-code-docs
For full configuration options, use the configurator at mcp.apify.com.
How it works
- One script per run. The Actor reads your
code, runs it once, writes the result, and exits. - The code runs inside a
workerdV8 isolate: no filesystem, no package imports, and outbound network is restricted to*.apify.com. - Inside the script a global
apifyobject exposes a small, typed subset of the Apify API — run Actors, read/write datasets and key-value stores — using the current run's token (see below). console.log/console.infogo to stdout;console.error/console.warngo to stderr. The two streams are captured separately.
Input
{"code": "const { items } = await apify.actor.runAndGetItems({ actorId: 'apify/rag-web-browser', input: { query: 'apify' }, limit: 3 });\nconsole.log(items.map((i) => i.metadata?.title).join('\\n'));"}
| Field | Type | Description |
|---|---|---|
code | string | The TypeScript/JavaScript script to run. It receives the apify binding and console. |
Output
A single dataset item with the captured streams:
{ "stdout": "Apify: Full-stack web scraping ...\n...", "stderr": "" }
If the script throws, the error lands in stderr; stdout keeps whatever was
printed before the failure.
Permissions & safety
- Runs with limited permissions: the sandbox has no filesystem and can reach
only the Apify API (
*.apify.com). - Each run is an isolated, single-use container — nothing persists between runs.
The apify binding
Every method takes one options object and returns parsed JSON
(? = optional, = x = default). Full API documentation is available
here.
// Actorsapify.actor.search({ query, limit?, category? }) // → actors[]apify.actor.getDetails({ actorId }) // → actorapify.actor.start({ actorId, input?, memoryMbytes?, timeoutSecs?, maxTotalChargeUsd?, maxItems? }) // → runapify.actor.run({ actorId, ...startOpts, waitForFinishSecs = 60 }) // → run (waits)apify.actor.runAndGetItems({ actorId, input?, fields?, limit?, ...runOpts }) // → { run, items }// Runsapify.run.get({ runId }) // → runapify.run.wait({ runId, waitForFinishSecs = 60 }) // → runapify.run.abort({ runId }) // → runapify.run.getLog({ runId, limit? }) // → string// Datasetsapify.dataset.create({ name? }) // → datasetapify.dataset.pushItems({ datasetId, items }) // → voidapify.dataset.listItems({ datasetId, fields?, omit?, limit?, offset?, clean?, desc? }) // → items[]apify.dataset.iterate({ datasetId, batchSize = 1000, ...filters }) // → async iterableapify.dataset.getSchema({ datasetId, sample = 5 }) // → { itemCount, fields[] }// Key-value storesapify.kvs.create({ name? }) // → storeapify.kvs.set({ storeId, key, value, contentType? }) // → voidapify.kvs.get({ storeId, key }) // → value | nullapify.kvs.list({ storeId, limit?, exclusiveStartKey? }) // → { items }
Learn more
- Apify MCP Server: https://mcp.apify.com
- Code Mode design: apify/apify-mcp-server#794


