BACKEND API · FASTAPI & PYTHON

pyflow

Safely execute Python code in isolated subprocesses with real-time streaming output and contextual AI error analysis.

Framework
FastAPI + Uvicorn
Isolation
Subprocess Sandboxing
AI Routing
Multi-Provider Chat
Streaming
Server-Sent Events (SSE)

Executive TL;DR — Engineering Brief

PyFlow is an open source developer tool crafted by Alex Santos. It provides an isolated local execution runtime for Python code, accompanied by contextual AI explanations for tracebacks and interactive debugging chat.

DIAGRAM & WORKFLOW

Sandboxed Execution Architecture

Isolated subprocess execution with memory/timeout boundaries and streaming stdout/stderr capture.

DETAILED ENGINEERING

Core Technical Pillars

Design choices, architectural patterns, and engineering decisions implemented for extreme reliability and developer experience.

01

Subprocess Sandboxing with Strict Resource Limits

Guards against runaway loops, excessive allocations, and hung threads

Spawns isolated child processes with enforced execution timeouts and signal handling (SIGTERM/SIGKILL), isolating host memory.

02

Contextual AI Traceback Diagnostics

Analyzes exceptions and recommends actionable code remedies

When an exception occurs, PyFlow sends the traceback, relevant variables, and code chunk to an LLM to deliver clean, concise explanations.

03

Real-Time Log & Output Streaming

SSE (Server-Sent Events) for instant execution visibility

Streams stdout and stderr directly to connected clients in real time, delivering an interactive REPL-like experience.

04

Multi-Provider LLM Integration

Configurable endpoints for Google Gemini, OpenAI, and Ollama

Switch between cloud providers or fully local Ollama models with a single environment variable change.

CODE IN ACTION

FastAPI Endpoint Example

Real-world usage, terminal configuration, and technical integration commands.

Terminal Example SHELL
from fastapi import FastAPI
from pydantic import BaseModel
import subprocess

app = FastAPI(title="PyFlow API")

class CodeExecutionRequest(BaseModel):
    code: str
    timeout_seconds: int = 10

@app.post("/api/execute")
async def execute_code(req: CodeExecutionRequest):
    # Runs in isolated subprocess with timeout
    result = subprocess.run(
        ["python", "-c", req.code],
        capture_output=True,
        text=True,
        timeout=req.timeout_seconds
    )
    return {
        "stdout": result.stdout,
        "stderr": result.stderr,
        "exit_code": result.returncode
    }
QUESTIONS & ANSWERS

Technical Frequently Asked Questions

Key clarifications regarding licensing, compatibility, deployment, and security.

Can PyFlow execute packages installed in the local environment?

Yes, it runs against the active Python virtual environment (venv).

What security measures prevent hostile code?

Execution timeouts, subprocess isolation, and optional containerization via Docker.

Can I connect custom frontend interfaces?

Yes, PyFlow exposes standard OpenAPI/Swagger REST endpoints and SSE streams.

Is GPU execution supported?

Yes, scripts requiring PyTorch or CUDA have direct access to available GPUs.