Skip to main content

python_exec


Python Code

Type: python_exec • Category: flow • Tags: python, exec, sandbox

Description

Execute limited Python code (numpy, pandas, math)

Parameters

NameTypeDescriptionRequiredDefault
codecodeMultiline Python codeno
persistentbooleanUse persistent worker process (faster for multiple calls)nofalse

Help

Overview

This worker provides a lightweight sandbox for executing Python snippets that rely on the NumPy, pandas, and math libraries. It is designed for quick, single‑call evaluations as well as repeated calls when the persistent mode is enabled, offering a balance between flexibility and performance.

Inputs

  • codestring (multiline)
    The Python source to be executed. The code may import and use numpy, pandas, and math but cannot access the broader system or external services.
  • persistentboolean, default false
    When set to true, the worker keeps the Python interpreter alive across multiple invocations, reducing start‑up overhead for batch processing.

Minimal Example Usage

  1. Prepare the request payload:

    code: "import numpy as np\nresult = np.mean([1, 2, 3])"

    persistent: false

  2. Send the payload to the worker endpoint.

  3. The response will contain the value of result (e.g., 2.0).

If you need to run several related snippets, set persistent: true in the first call and reuse the same worker for subsequent calls.

Notes

  • Only the three whitelisted libraries are available; attempts to import other modules will raise an error.
  • The worker runs in a restricted environment, so operations that require file I/O, network access, or system commands are prohibited.
  • Persistent mode is ideal for workloads such as data‑frame transformations or iterative numerical calculations where the interpreter start‑up cost becomes noticeable.