Execute 5 credits COMPUTE

Run JavaScript in Sandbox API

Execute JavaScript code strings in an isolated, sandboxed Node.js VM environment via REST API. The sandbox has no access to the filesystem, network, or Node.js process — making it safe to run untrusted or user-provided code and return the result.

Try it live →

How it works

POST a JavaScript code string. The API executes it inside a vm.runInNewContext() sandbox with a configurable timeout (default 5 seconds). Returns the return value of the last expression, all console.log output captured as an array, execution time in milliseconds, and any thrown errors.

Use cases

API Reference

POST https://slopshop.gg/v1/exec-javascript
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Input parameters

ParameterTypeRequiredDescription
input string | object required The input data to process

Example response

{
  "data": {
    "result": 42,
    "console": [],
    "execution_ms": 3
  },
  "meta": {
    "credits_used": 5,
    "engine": "real",
    "ms": 4
  }
}

Examples

Three real-world scenarios showing how developers use Run JavaScript in Sandbox in production.

Example 1
Run a transformation function
Execute a data transformation written in JS on the fly.
curl -X POST https://slopshop.gg/v1/exec-javascript \
  -H "Authorization: Bearer $SLOPSHOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{"code": "const data = [1,2,3,4,5]; return data.map(x => x * 2).filter(x => x > 4);"}'
Example 2
Evaluate a user formula
Execute a user-provided formula from a no-code tool safely.
curl -X POST https://slopshop.gg/v1/exec-javascript \
  -H "Authorization: Bearer $SLOPSHOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{"code": "const revenue = 150000; const cost = 87000; return ((revenue - cost) / revenue * 100).toFixed(2) + '%';"}'
Example 3
Test a sorting algorithm
Run an agent-generated sorting implementation to verify correctness.
curl -X POST https://slopshop.gg/v1/exec-javascript \
  -H "Authorization: Bearer $SLOPSHOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{"code": "function bubbleSort(arr) { for(let i=0;iarr[j+1]) [arr[j],arr[j+1]]=[arr[j+1],arr[j]]; return arr; } return bubbleSort([5,3,8,1,9,2]);"}'

Code examples

curl

curl -X POST https://slopshop.gg/v1/exec-javascript \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"input": "your data here"}'

Python

import requests

response = requests.post(
    "https://slopshop.gg/v1/exec-javascript",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={"input": "your data here"}
)
result = response.json()
print(result["data"])

Node.js

const response = await fetch("https://slopshop.gg/v1/exec-javascript", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({ input: "your data here" })
});
const { data } = await response.json();
console.log(data);

CLI

# Install the Slopshop CLI
npm install -g slopshop

# Set your API key
export SLOPSHOP_KEY=your_api_key

# Call exec-javascript
slop exec-javascript '{"input": "your data here"}'

Pricing

Credits per call
5
credits
Cost per call
$0.005
at Starter tier
Tier
COMPUTE
Pure compute

Credits are purchased in bundles starting at $1 for 1,000 credits. All compute APIs like this one use 5 credits per call — that's $0.005. See all pricing tiers.

Related APIs in Execute

View the full API catalog · Try in playground · Documentation