Description

This endpoint allows you to run JavaScript code in a secure sandbox environment. The code is executed using a secure code interpreter and returns both stdout and stderr logs.

Endpoint

POST /api/v1/run-js-code

Headers

  • Content-Type: application/json
  • Authorization: Bearer <API_KEY> (required)

Request Body

{
  "commands": "string", // Optional. Install NPM packages before code execution e.g. npm install axios
  "code": "string", // Required. The JavaScript code to be executed
  "parseJson": boolean, // Optional. Whether to parse stdout/stderr as JSON
}

Responses

Success (200)

Returns the output logs from the executed JavaScript code.

{
  "logs": {
    "stdout": string[] | any, // Array of stdout messages or parsed JSON
    "stderr": string[] | any  // Array of stderr messages or parsed JSON
  }
}
  • Content-Type: application/json
  • X-RateLimit-Limit: The rate limit for the user
  • X-RateLimit-Remaining: The remaining number of requests for the user

Bad Request (400)

Returned if the request is missing required parameters.

{
  "error": "code parameter is required"
}

Internal Server Error (500)

Returned if there’s an error during code execution.

{
  "error": {
    "name": "string",
    "value": "string",
    "traceback": "string"
  }
}

Example Request

curl -X POST https://app.dumplingai.com/api/v1/run-js-code \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
  "commands": "npm install axios",
  "code": "console.log(JSON.stringify({ hello: \"world\" }));",
  "parseJson": true
}'

Example Response

{
  "logs": {
    "stdout": { "hello": "world" },
    "stderr": []
  }
}

Notes

  • This endpoint uses 5 credits per request
  • Code execution timeout is set to 10 seconds
  • The code is executed in a secure sandbox environment
  • When parseJson is true, the system will attempt to parse stdout and stderr as JSON
  • You can install NPM packages by using the commands parameter e.g. npm install axios

Rate Limiting

Rate limit headers (X-RateLimit-Limit and X-RateLimit-Remaining) are included in the response to indicate the user’s current rate limit status.