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
- Run user-submitted JavaScript formulas in a no-code tool or spreadsheet
- Execute transformation logic in an ETL pipeline without deploying code
- Test JavaScript snippets in CI without spinning up a full Node.js environment
- Build a code playground or REPL in a web app without server infrastructure
- Run agent-generated code safely to verify its output before deployment
API Reference
POST https://slopshop.gg/v1/exec-javascript
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Input parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
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.
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);"}'
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) + '%';"}'
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 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