> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dumplingai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Run JavaScript Code

> Execute sandboxed JavaScript and return stdout, stderr, and logs.

## 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 https://app.dumplingai.com/api/v1/run-js-code
```

## Headers

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

## Request Body

```json theme={null}
{
  "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.

```json theme={null}
{
  "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.

```json theme={null}
{
  "error": "code parameter is required"
}
```

### Internal Server Error (500)

Returned if there's an error during code execution.

```json theme={null}
{
  "error": {
    "name": "string",
    "value": "string",
    "traceback": "string"
  }
}
```

## Example Request

```bash theme={null}
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

```json theme={null}
{
  "logs": {
    "stdout": { "hello": "world" },
    "stderr": []
  }
}
```

## Notes

* This endpoint uses 50 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.


## OpenAPI

````yaml POST /api/v1/run-js-code
openapi: 3.0.3
info:
  title: DumplingAI API
  version: 1.0.0
  description: >
    REST API for DumplingAI's content intelligence and automation platform.

    All endpoints are grouped under `/api/v1`; most are secured via Bearer API
    keys unless an operation explicitly sets `security: []`.
servers:
  - url: https://app.dumplingai.com
    description: Production
security:
  - bearerAuth: []
tags:
  - name: YouTube
    description: Access metadata, search results, and transcripts from YouTube.
  - name: TikTok
    description: Retrieve TikTok profile, video, follower, and transcript data.
  - name: LinkedIn
    description: Programmatically fetch LinkedIn company and profile data.
  - name: Search
    description: Search-orientated endpoints spanning web, news, maps, and autocomplete.
  - name: Google
    description: Integrations with Google business listings and location data.
  - name: Scraping
    description: Webpage capture, crawling, and structured content extraction utilities.
  - name: Documents
    description: Document processing, conversion, and metadata utilities.
  - name: AI
    description: DumplingAI agent and knowledge base endpoints.
  - name: Developer Tools
    description: Utilities for executing sandboxed code via API.
paths:
  /api/v1/run-js-code:
    post:
      tags:
        - Developer Tools
      summary: Run JavaScript code
      description: Execute sandboxed JavaScript and return stdout, stderr, and logs.
      operationId: runJsCode
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CodeExecutionRequest'
            examples:
              default:
                value:
                  code: export default async function main() { return 'hello'; }
      responses:
        '200':
          description: Execution results returned.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CodeExecutionResponse'
        '400':
          description: Invalid request payload.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Missing or invalid API key.
        '500':
          description: Unexpected server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    CodeExecutionRequest:
      type: object
      description: Request payload for sandboxed code execution.
      required:
        - code
      properties:
        code:
          type: string
          description: Source code to execute inside the sandbox.
        commands:
          type: array
          description: Shell commands to run before executing the code.
          items:
            type: string
        parseJson:
          type: boolean
          description: Attempt to parse stdout/stderr as JSON arrays.
        requestSource:
          $ref: '#/components/schemas/RequestSource'
      additionalProperties: false
    CodeExecutionResponse:
      type: object
      required:
        - logs
      properties:
        logs:
          type: object
          required:
            - stdout
            - stderr
          properties:
            stdout:
              $ref: '#/components/schemas/CodeExecutionLogValue'
            stderr:
              $ref: '#/components/schemas/CodeExecutionLogValue'
          additionalProperties: false
      additionalProperties: false
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: Human-readable description of what went wrong.
      required:
        - error
    RequestSource:
      type: string
      description: Optional identifier describing where the API request originated.
      enum:
        - API
        - WEB
        - MAKE_DOT_COM
        - ZAPIER
        - N8N
        - PLAYGROUND
        - DEFAULT_AUTOMATION
        - AGENT_PREVIEW
        - AGENT_LIVE
        - AUTOPILOT
        - STUDIO
    CodeExecutionLogValue:
      description: >-
        Captured log output, returned either as raw lines or parsed JSON when
        `parseJson` is enabled.
      oneOf:
        - type: array
          items:
            type: string
        - type: object
          additionalProperties: true
        - type: array
          items: {}
        - type: string
        - type: number
        - type: boolean
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key

````