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

# Code Runner

> Execute JavaScript and Python code snippets within your workflows.

The Code Runner connector lets you run custom JavaScript or Python code inside your workflows. Use it for custom logic, data transformations, and calculations that aren't covered by the built-in utility connectors.

<Note>No connection required. This utility connector works out of the box.</Note>

## Tools

<AccordionGroup>
  <Accordion title="execute-javascript: Run JavaScript">
    Execute JavaScript code in a sandboxed VM environment.

    <ParamField body="code" type="string" required>
      JavaScript code to execute.
    </ParamField>

    <ParamField body="input" type="any">
      Input data, available in the code as the `data` variable.
    </ParamField>

    <ParamField body="timeout" type="number" default="5000">
      Execution timeout in milliseconds (max 30000).
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "code": "const total = data.items.reduce((sum, n) => sum + n, 0);\nconsole.log('Processing', data.items.length, 'items');\nreturn { total, average: total / data.items.length };",
      "input": {
        "items": [10, 20, 30, 40]
      },
      "timeout": 5000
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "success": true,
      "result": "[object Object]",
      "stdout": "Processing 4 items",
      "stderr": "",
      "executionTime": 3
    }
    ```
  </Accordion>

  <Accordion title="execute-python: Run Python">
    Execute Python code in a sandboxed environment.

    <ParamField body="code" type="string" required>
      Python code to execute.
    </ParamField>

    <ParamField body="input" type="any">
      Input data, available in the code as the `data` variable.
    </ParamField>

    <ParamField body="timeout" type="number" default="5000">
      Execution timeout in milliseconds (max 30000).
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "code": "import re\n\nemails = re.findall(r'[\\w.+-]+@[\\w-]+\\.[\\w.]+', data['text'])\nprint(f'Found {len(emails)} emails')\n{'emails': emails, 'count': len(emails)}",
      "input": {
        "text": "Contact us at support@example.com or sales@example.com for help."
      },
      "timeout": 5000
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "success": true,
      "result": "{'emails': ['support@example.com', 'sales@example.com'], 'count': 2}",
      "stdout": "Found 2 emails",
      "stderr": "",
      "executionTime": 85
    }
    ```
  </Accordion>
</AccordionGroup>

## Tips

* Use the `data` variable to access input passed from previous workflow nodes.
* Keep code focused; for simple transformations, consider using the [JSON Tools](/connectors/utilities/json) or [Text Tools](/connectors/utilities/text) connectors instead.
* Both JavaScript and Python run in isolated environments with limited access to system resources.
* Set an appropriate timeout for long-running computations.
