Skip to main content

Type

python

Variants

Restricted Imports, Full Access
Purpose: The Python skill enables agents to execute Python code with fine-grained control over module imports, execution environment, and resource limits.

Common Use Cases

Data processing and analysisParse, transform, and analyze data with Python libraries

Running Python scriptsExecute automation scripts, data pipelines, and workflows

API integrationsCall external APIs using requests, handle OAuth, process responses

Custom business logicImplement complex algorithms and domain-specific operations

Variants Overview

VariantSecurityKey PermissionsBest ForCreate Command
Restricted Imports 🟢SafeStandard library modules onlyData processing, safe scripting--variant restricted_imports
Full Access 🔴UnrestrictedAll modules, third-party packagesData science, ML workflows--variant full_access
Choosing a variant: Start with Restricted Imports and only upgrade to Full Access when third-party packages are required. See Variant Configuration for detailed differences.

Configuration

Example Configuration:
{
  "allowed_imports": ["json", "csv", "datetime", "re", "math"],
  "timeout": 120,
  "max_memory": "512MB",
  "working_directory": "/workspace"
}
ParameterTypeDefaultDescription
allowed_importsarrayvariant-specificWhitelist of allowed Python modules
timeoutnumber120Execution timeout in seconds
max_memorystring”512MB”Memory limit for Python process
max_output_sizestring”10MB”Maximum output capture size
working_directorystring”/“Execution directory
environment_variablesobjectCustom environment variables
Restricted Imports:
  • allowed_imports: Standard library safe modules (json, csv, datetime, re, math, collections, itertools, etc.)
  • Network and shell access modules blocked
Full Access:
  • allowed_imports: [”*”] (all modules)
  • Third-party packages allowed
  • Higher default limits: max_memory: "2GB", timeout: 600
See: Variant Configuration Guide

Quick Start

# Create skill with variant
kubiya skill create --name "Data Processor" --type python --variant restricted_imports --enabled

# Associate with agent
kubiya skill associate agent <agent-id> <skill-id>

View Complete Examples

See full data analysis patterns, API integration workflows, and ML pipeline configurations

Python Code Execution

Inline Code Example

Agents can execute Python code directly:
import json
import datetime

data = {
    "timestamp": datetime.datetime.now().isoformat(),
    "status": "success",
    "results": [1, 2, 3, 4, 5]
}

print(json.dumps(data, indent=2))

Script Execution

Agents can run Python scripts from the filesystem:
# /opt/scripts/process_logs.py
import sys
import json
from datetime import datetime

def analyze_logs(log_file):
    # Log processing logic
    results = {"processed": True, "count": 42}
    return results

if __name__ == "__main__":
    result = analyze_logs(sys.argv[1])
    print(json.dumps(result))

Installing Additional Packages

For agents that need third-party packages, install them on the worker:
# On the worker system
pip install requests pandas numpy

# Or use requirements.txt
pip install -r /opt/agent-requirements.txt
Then allow imports in the skill configuration:
{
  "allowed_imports": ["requests", "pandas", "numpy"]
}
Package Management: Packages must be installed on the worker system before agents can import them. Coordinate with your infrastructure team for package deployment.

Security Best Practices

Only allow the specific Python modules your agent needs.
# Good: Specific imports
allowed_imports: ["json", "csv", "datetime"]

# Risky: Too permissive
allowed_imports: ["*"]  # Allows everything
Always configure max_memory to prevent resource exhaustion.
max_memory: "512MB"  # Prevents memory exhaustion
Set reasonable timeouts to prevent infinite loops.
timeout: 120  # Scripts automatically terminate after 2 minutes
Performance Tip: For data-heavy operations, consider increasing max_memory and timeout values appropriately.

Solutions:
  • Add module to allowed_imports in configuration
  • Verify module name exactly matches Python import (e.g., urllib.parse not urllib)
  • Consider upgrading to Full Access variant if appropriate
Solutions:
  • Verify package is installed on worker: pip list | grep package-name
  • Ensure PYTHONPATH includes package location
  • Install missing package: pip install package-name
Solutions:
  • Increase max_memory in configuration
  • Optimize script to use less memory (streaming, generators)
  • Process data in smaller batches