A practical demo accompanying the article "Create Your Own Sandboxed Code Generation Agent in Minutes" showing how to build your own code generation agent that actually executes the code it writes. Built with Atomic Agents and Cohere Terrarium.
This demo creates an AI agent that:
- Generates Python code based on your requirements
- Executes it in a sandboxed environment
- Shows you the results
The cool part? It uses Terrarium to safely run the generated code in a WebAssembly sandbox - no need to worry about malicious code execution.
- Python 3.9+
- Docker & Docker Compose
- Poetry (for dependency management)
-
Clone this repo and install dependencies:
git clone <repo-url> cd code-gen-agent poetry install
-
Fire up Terrarium:
cd cohere-terrarium docker-compose up -d
-
Set your OpenAI API key:
export OPENAI_API_KEY=your-key-here
Run the demo:
poetry run python code_gen_agent/main.py
This will generate a text analyzer that counts words, calculates average word length, and finds the most frequent word.
For demo purposes, the user request for which code to generate is hardcoded inside the main.py
file so feel free to change it to something else and have a play around!
The magic happens in just two main components:
- CodeGenerationAgent: Handles the code generation using GPT-4o-mini
- TerrariumTool: Manages code execution in the sandboxed environment
MIT - do whatever you want with it.