ShVaSa Blog
Systems & RL • 4 min read

Don't Write Markdown Files for Your Coding Agent. Write Scripts.

Published on 2026-11-05 by Sharath Japa, ShVaSa Lab Lead
systemsarchitectureinfrastructureperformance
Discuss on r/shvasa

Executive Summary

The prevailing paradigm of Large Language Model (LLM) agents operating on static Markdown task definitions introduces a critical failure mode: semantic drift and non-deterministic execution. Markdown, while human-readable, lacks the strict type safety, atomicity, and verifiable state transitions required for robust systems engineering. By shifting the agent’s operational context from static documentation to executable scripts (Python/Bash), we enforce a "code-as-contract" model. This transition reduces hallucination rates by mandating that the agent’s output be syntactically valid and semantically executable before it enters the runtime environment. The core argument is that verification must precede execution, and scripts provide the only viable mechanism for pre-flight validation of agent intent against system constraints.

Implementation

The transition from Markdown directives to executable scripts requires a fundamental change in how we define the "task." In a Markdown-based workflow, a task is a description. In a script-based workflow, a task is a function call or a shell command with explicit input/output contracts.

Consider a typical data processing pipeline. A Markdown agent might generate a script that "fetches data and cleans it." This is ambiguous. A script-based agent generates a Python function with type hints, explicit error handling, and a verification step. The key bottleneck here is not computational complexity, but the verification overhead required to ensure the generated script does not violate system constraints (e.g., memory limits, network timeouts).

We implement this using a two-stage process:

  1. Generation: The LLM generates a Python script that adheres to a strict schema.
  2. Validation: A static analysis tool (e.g., pylint, mypy) and a lightweight sandboxed execution environment verify the script’s structure and side effects before it is deployed.
PYTHON
import subprocess
import sys
import tempfile
import os

def verify_and_execute_agent_script(script_content: str) -> dict:
    """
    Validates and executes an agent-generated Python script.
    Returns a status dictionary with execution results.
    """
    # 1. Static Analysis: Check for syntax errors and common pitfalls
    try:
        compile(script_content, '<agent_generated>', 'exec')
    except SyntaxError as e:
        return {"status": "error", "message": f"Syntax Error: {e.msg}"}

    # 2. Security Check: Block dangerous imports or system calls
    dangerous_patterns = ['os.system', 'subprocess.call', '__import__']
    for pattern in dangerous_patterns:
        if pattern in script_content:
            return {"status": "error", "message": f"Security Violation: {pattern} found"}

    # 3. Execution: Run in a sandboxed environment (simulated here)
    with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
        f.write(script_content)
        temp_path = f.name

    try:
        result = subprocess.run(
            [sys.executable, temp_path],
            capture_output=True,
            text=True,
            timeout=30  # Enforce time limits to prevent infinite loops
        )
        return {
            "status": "success" if result.returncode == 0 else "failed",
            "stdout": result.stdout,
            "stderr": result.stderr,
            "returncode": result.returncode
        }
    except subprocess.TimeoutExpired:
        return {"status": "error", "message": "Execution timed out"}
    finally:
        os.unlink(temp_path)

# Example usage
agent_output = """
def process_data(data):
    return [x * 2 for x in data]

if __name__ == "__main__":
    print(process_data([1, 2, 3]))
"""

print(verify_and_execute_agent_script(agent_output))

ShVaSa Intuition

The core intuition behind ShVaSa is that ambiguity is the enemy of determinism. Markdown is inherently ambiguous. A statement like "optimize the query" can mean anything from adding an index to rewriting the entire SQL structure. An LLM, trained on vast corpora of natural language, will interpret this based on probabilistic patterns, often leading to hallucinated or suboptimal solutions.

Scripts, however, are unambiguous. A Python function with type hints and docstrings defines a precise contract. The agent’s job shifts from "writing a description" to "implementing a specification." This reduces the search space for the LLM, as it must now produce syntactically correct code that satisfies the type constraints.

Furthermore, scripts enable pre-execution verification. Before a script is run, we can analyze its AST (Abstract Syntax Tree) to ensure it adheres to security policies, resource limits, and best practices. This is impossible with Markdown, where verification is post-hoc and manual.

The bottleneck in this approach is the verification latency. Static analysis and sandboxed execution add overhead. However, this overhead is negligible compared to the cost of debugging a hallucinated agent output in production. The trade-off is clear: invest in rigorous pre-flight checks to eliminate runtime failures.

Architecture

The following Mermaid diagram illustrates the flow of an agent task from intent to execution in a script-based system.

sequenceDiagram
    participant User
    participant Agent as LLM Agent
    participant Validator as Static Analyzer
    participant Sandbox as Execution Environment
    participant System

    User->>Agent: Define task in natural language
    Agent->>Agent: Generate Python script
    Agent->>Validator: Send script for validation
    Validator->>Validator: Check syntax & security
    alt Validation Fails
        Validator-->>Agent: Return error
        Agent->>Agent: Refine script
        Agent->>Validator: Resubmit
    else Validation Passes
        Validator-->>Sandbox: Execute script
        Sandbox->>System: Run with constraints
        Sandbox-->>Validator: Return output/status
        Validator-->>Agent: Confirm success
        Agent-->>User: Report results
    end

Conclusion

Replacing Markdown task directives with executable scripts is not merely a stylistic choice; it is a fundamental architectural decision that enhances reliability, security, and determinism. By enforcing strict contracts and enabling pre-execution verification, we mitigate the risks associated with LLM hallucinations. The future of AI-driven systems engineering lies in code-centric workflows, where every agent output is treated as a potential executable artifact, subject to rigorous validation before deployment.

<!-- Consensus Verified by Student (qwen3.6-35b-a3b) & Judge (gemma-4-31b-it) | VERIFICATION REPORT -->


Grounding & Source Attribution

Author Avatar

Sharath Japa, ShVaSa Lab Lead

Systems & AI Infrastructure Researcher, DGX Station homelab lead. Engineering RL environments, edge silicon inference, and local reasoning model distillation. Verified Profiles: Google Scholar • Google Patents • LinkedIn • GitHub (@sharathjapa) • Medium • r/shvasa.


Canonical Source: https://shvasa.us/posts/dont-write-markdown-files-for-your-coding-agent-write-scripts

Advertisement

Related Research & Architectural Blueprints