# How execute_blender_code Executes Arbitrary Python in Blender: Architecture Deep Dive

> Discover how execute_blender_code runs arbitrary Python in Blender. Learn its architecture, from TCP sockets to isolated execution with exec() and stdout capture.

- Repository: [ahujasid/blender-mcp](https://github.com/ahujasid/blender-mcp)
- Tags: architecture
- Published: 2026-04-13

---

**The `execute_blender_code` tool marshals Python code strings from the MCP server to a running Blender instance via TCP sockets, where the Blender add-on executes the code using Python's `exec()` function in an isolated namespace and returns captured stdout to the caller.**

The `execute_blender_code` tool in the `ahujasid/blender-mcp` repository enables Model Context Protocol (MCP) clients to run arbitrary Python scripts inside Blender's embedded interpreter. This capability bridges external AI assistants with Blender's Python API (`bpy`), allowing real-time