Execute Javascript Code avatar
Execute Javascript Code

Pricing

from $0.01 / 1,000 results

Go to Apify Store
Execute Javascript Code

Execute Javascript Code

Execute JavaScript code securely. Pay only for the seconds you use, starting from $1/hour. Supports multiple code blocks, custom timeouts, and detailed output capture (stdout/stderr). Fast, secure, and cost-effective for dynamic code execution tasks.

Pricing

from $0.01 / 1,000 results

Rating

0.0

(0)

Developer

Rixin Sc

Rixin Sc

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

2 days ago

Last modified

Share

What does Execute Javascript Code do?

Execute Javascript Code allows you to run arbitrary JavaScript code blocks securely in the cloud using the high-performance Bun runtime. It provides a flexible and cost-effective way to execute dynamic logic, perform calculations, or run one-off scripts without managing infrastructure.

  • Execute arbitrary JavaScript: Run valid JavaScript code immediately.
  • High Performance: Powered by the Bun runtime for fast startup and execution.
  • Secure Isolation: Each execution runs in a restricted environment where the main actor script deletes itself to prevent introspection.
  • Pay-Per-Second: You are charged only for the exact execution time (minimum 1 second), making it extremely affordable (~$1.00/hour).
  • Detailed Output: Capture stdout, stderr, exit codes, and precise execution timing.
  • Flexible Input: Support for single code snippets or batched code blocks with individual timeouts.

What data can you get?

This Actor returns detailed information about the execution of your code blocks.

🆔 Code Block ID📤 Stdout⚠️ Stderr
🚪 Exit Code⏱️ Execution Time💲 Charged Seconds
❌ Error Details📅 Timestamp

How to use Execute Javascript Code?

It's easy to get started with executing JavaScript code in the cloud.

  1. Create a free Apify account.
  2. Open Execute Javascript Code.
  3. Enter the JavaScript code you want to run in the input field.
  4. Click "Start" and wait for the execution to complete.
  5. Download your results in JSON, CSV, or other formats.

Input

The input is a JSON object where you can specify the code to execute. You can provide a single code string or a list of code blocks with custom configurations.

  • code: A single string of JavaScript code to execute.
  • codeBlocks: An array of objects, each containing code and optional id and timeout.
  • timeout: Global default timeout in seconds (default: 60s, max: 7200s).

Input Example (Single Block)

{
"code": "console.log('Hello from Apify!');"
}

Input Example (Multiple Blocks)

{
"codeBlocks": [
{
"id": "calculation",
"code": "console.log(Math.PI * Math.pow(5, 2));",
"timeout": 5
},
{
"id": "async-operation",
"code": "await new Promise(r => setTimeout(r, 1000)); console.log('Done');",
"timeout": 10
}
],
"timeout": 30
}

Output

The results are stored in the default dataset. Each item represents the execution result of one code block.

Output Example

{
"codeBlockId": "calculation",
"stdout": "78.53981633974483\n",
"stderr": "",
"exitCode": 0,
"executionTimeSeconds": 0.015,
"chargedSeconds": 1,
"error": null,
"executedAt": "2023-10-27T10:00:00.000Z"
}

Integrations

You can integrate Execute Javascript Code with almost any cloud service or web app.

  • Make & Zapier: Trigger code execution from other workflows.
  • Slack & Discord: Send notifications based on execution results.
  • Google Sheets: Process data from sheets using custom JS logic.
  • Webhooks: Receive immediate notifications when your code finishes running.

FAQ

How much does it cost?

This Actor uses the Pay-Per-Event (PPE) pricing model.

  • Price: $0.000278 per second of execution time (approx. $1.00 per hour). Check latest pricing from the pricing tab.
  • Minimum: 1 second per block. You pay only for what you use.

Can I use Execute Javascript Code with the Apify API?

Yes. The Apify API gives you programmatic access to the Apify platform. You can manage, schedule, and run Actors, access datasets, monitor performance, and more. To access the API using Node.js, use the apify-client NPM package. To access the API using Python, use the apify-client PyPI package.

Can I use this Actor through an MCP Server?

Yes. You can use this Actor in conjunction with an MCP server to enable AI assistants to execute code.

  1. Set up the Apify MCP server.
  2. Allow the tool actor-run or similar.
  3. The AI model can then invoke this Actor to run calculations or logic and get the results back.

Your feedback

We’re always working on improving the performance of our Actors. If you have any technical feedback or found a bug, please create an issue in the Issues tab.