[Vibe Coding Masterclass Part 2] Building a ‘Safe Playground’ for AI: Sandbox and File Management

💡 What You Will Learn

Now that we’ve set up the workbench (Harness) in Part 1, it’s time to ensure your AI ‘stays within the lines’ while delivering peak performance.

Practical Skills in this Guide:
1. How a Sandbox works to protect your computer’s security.
2. Managing File Fidelity so your project doesn’t break even when AI touches thousands of files.
3. The process of safely building the Backend Engine, the heart of USETFAnalysis.


1. “AI just wiped out all my source code!”

This is a scream often heard in Vibe Coding communities. You turn on the agent mode, grab a coffee, and come back to find the AI has deleted core logic or installed the wrong libraries, messing up your entire environment.

This disaster happens because you didn’t provide a ‘Sandbox’ for the AI. Just as children should only play with sand inside the sandbox to keep the living room clean, your AI agent should only edit and execute code within predefined boundaries.


2. The Core of Harness Architecture: Sandbox Isolation

A Sandbox is a technology that physically or logically separates the environment where an AI agent executes code and modifies files.

🛡️ Why is a Sandbox critical?

  1. Riot Prevention: Prevents buggy code from falling into infinite loops or hogging 100% of system resources.
  2. Enhanced Security: Fundamentally blocks AI from accessing encrypted personal info or critical system root folders.
  3. Environment Reproducibility: Allows you to instantly revert to a clean state if a task fails.

📝 Sandbox Strategy Comparison

  • Logical Isolation: Folder permissions & .cursorrules | (Pros) Easy setup | (Cons) AI might ignore rules | Recommended: Beginner (⭐⭐⭐⭐⭐)
  • Env Isolation: Python venv, Conda, nvm | (Pros) Perfect conflict prevention | (Cons) System file access allowed | Recommended: Intermediate (⭐⭐⭐⭐)
  • Container Isolation: Docker-based workspace | (Pros) High security & independence | (Cons) Docker setup overhead | Recommended: Advanced (⭐⭐⭐)
  • Cloud Isolation: E2B, VM, external servers | (Pros) Zero touch on local machine | (Cons) API costs & latency | Recommended: Expert (⭐⭐)

[Process Map] Code Execution Flow within a Sandbox

graph TD
    User([User Request]) --- Engine
    
    subgraph Sandbox_Engine ["Sandbox Engine Flow"]
        direction TB
        Input["1. AI Agent: Send execution command (uvicorn...)"]
        Boundary["2. Sandbox Boundary: Run within virtual env"]
        Filter["3. Filter: Block access to critical system files"]
        Response["4. Feedback: Return stdout & error results"]
        
        Input --> Boundary
        Boundary --> Filter
        Filter --> Response
    end
    
    Response --- Final([Safe Execution & Verification Complete])

    style Sandbox_Engine fill:#fffbe6,stroke:#d4b106,stroke-width:2px

3. [Tutorial] Building the USETFAnalysis Backend Engine

Let’s now put the actual ‘heart’ of the project on the workbench we built in Part 1. This is where the harness’s file management capability shines.

Step 1. Setting the Border (The Rule of Law)

Before the AI writes a single line of code, you must set the law: “You can only play here.”

  • How: Create a .cursorrules file in the root folder and enter these ‘Iron Rules.’

Agent Control Directives (.cursorrules):
`markdown
[STRICT RULE]
1. All code modifications are restricted to the backend/ folder and its subdirectories.
2. When installing external libraries, you must record them in requirements.txt and ask for my approval.
3. Do not modify global system environment variables or access root directories.
`

Step 2. Implementing Backend Logic (Prompt Recipe)

Now, let’s order the backend to handle professional financial data. The key is instructing it to test safely within the sandbox.

🚀 Action Prompt 2 (Backend Implementation):
“We’re going to build a server in the backend/ folder using FastAPI to fetch ETF data.
1. Create endpoints using yfinance to fetch price, dividend, and ticker info for symbols like SPY and QQQ.
2. Use pydantic to strictly define response formats to ensure financial data accuracy.
3. Write all server code in main.py and perfectly configure requirements.txt for testing within the local harness.”

Step 3. Harness Functional Test (Automated Verification)

Once the AI has written the code, it’s time to check if it actually works. Don’t touch the terminal yourself—ask the AI.

  • Instruction: “Now, execute the backend server you just wrote and verify yourself that the API is working correctly by accessing /docs. If there are issues, fix them yourself and report back.”
  • Verification: If the AI reports “Server execution successful, API response verified” and updates task.md, you’ve succeeded.

4. Tips for Managing File Fidelity

AI sometimes changes file contents haphazardly during Vibe Coding. Here’s how to prevent that:

  • Atomic Commits: Tell the AI, “Modify and report only one feature (e.g., one API endpoint) at a time.”
  • Verifying Diffs: Before the AI saves a file, make sure to manually check the ‘red/green lines’ to see what changed. The eyes of the harness are ultimately the user’s review.

🎁 Sneak Peek: “Solving AI Amnesia”

A safe playground and a backend engine are now complete. But as the project grows, the AI will start forgetting the code it wrote yesterday. In Part 3, we’ll dive into Memory Harness technology, giving the AI ‘permanent memory’ to manage tens of thousands of lines of code without skipping a beat!


⚠️ Important Disclaimer (Standardized)

  1. Educational Purpose: All content, including code and strategies, is for educational and research purposes only.
  2. No Financial Advice: This is not financial advice. I am not a financial advisor.
  3. Risk Warning: Investing involves significant risk. Past performance does not guarantee future results.
  4. Software Liability: Any tools or code provided are “as-is” without warranty. Use at your own risk.

Leave a Comment