core.script.run_python
Execute a Python script.
Use this action to transform workflow data, import third-party
packages, or call Tracecat APIs from an isolated Python 3.12 sandbox.
Tracecat passes inputs as function arguments and returns the
function result as the action output.
Import Python packages
Add pinned package specifications todependencies, then import them
in your script. Set allow_network: true so Tracecat can install the
packages from PyPI. Tracecat caches installed packages between runs.
Import Tracecat SDK
The Tracecat SDK is already available in the Python sandbox. Importctx from tracecat_registry; do not add the SDK to dependencies.
Use clients such as ctx.cases, ctx.tables, ctx.variables, and
ctx.workflows. Each client also provides an async variant under
.aio, such as ctx.cases.aio.
SDK calls use the workflow’s internal authenticated execution context
and do not require allow_network: true.
Use ctx.tables.insert_rows to write multiple rows in one request.
For large inputs, transform the records first and split them into
bounded batches. The destination table must already contain matching
columns.
- Synchronous
- Asynchronous
Inputs
Python script to execute. Must contain at least one function. If multiple functions are defined, one must be named ‘main’. Returns the output of the function.
Whether to allow network access during script execution. Default is False. Set to True when installing PyPI dependencies or making external network requests.Default:
false.Optional list of Python package dependencies to install via pip. Packages are cached between executions for performance.Default:
null.Environment variables to set in the sandbox. Use this to inject secrets or configuration.Default:
null.Input data passed as function arguments to the main function. Keys must match the parameter names in the function signature. Missing parameters will receive
None.Default: null.Maximum execution time in seconds. Default is 300 seconds (5 minutes).Default:
300.