How etienneperot/safe-code-execution works
Project type and purpose
• This is an open-source Open WebUI addon that provides sandboxed code execution capabilities. It ships two plugin flavors:
a. A code execution function (a “Run code” button under AI messages)
b. A code execution tool (an LLM-callable tool that runs code autonomously)
• It relies on the safecode library to interface with a gVisor sandbox, ensuring untrusted code runs securely.
File structure
• Top-level directories
• .github/ → CI workflows for tests & linting
• build/ → packaging scripts (build_openwebui.py, versioning)
• docs/ → setup & developer guides
• open-webui/ → raw plugin definitions for Functions & Tools (what you copy into Open WebUI)
• res/ → screenshots & GIFs for documentation
• src/openwebui/ → Python modules defining how the plugin hooks into Open WebUI
• src/safecode/ → sandbox orchestration: sandbox.py, user_storage.py, update_check.py
• tests/ → shell tests for the function & tool
• Key patterns
– Plugin layer (src/openwebui/…)
– Sandbox core (src/safecode/…)
– Build & CI for packaging and quality gates
README for additional insights
• Confirms two integration points (Function vs Tool)
• Lists external dependencies: Python runtime, gVisor
• Describes installation steps in Open WebUI’s UI
a. Main components
1. Open WebUI Host (Frontend + Function/Tool registry)
2. Run Code Function plugin module
3. Run Code Tool plugin module
4. SafeCode Library (sandbox manager, user storage, update checker)
5. gVisor Sandbox (container runtime for untrusted code)
6. GitHub Actions CI (lint & test)
7. Build Scripts (package & version metadata)
b. Relationships & interactions
• User or LLM invokes Function or Tool in Open WebUI
• Plugin module calls into SafeCode Library API
• SafeCode spins up a gVisor sandbox, mounts user workspace via user_storage, executes code
• Sandbox returns stdout/stderr/results to the plugin → displayed back in Open WebUI
• Periodically, SafeCode runs an update_check to fetch new versions/configs
• Build Scripts package the plugin, CI workflows run tests against both open-webui/ copies and src/ modules
c. Architectural patterns & design principles
• Layered architecture: UI plugin layer → sandboxing core → external runtime
• Separation of concerns: plugin definitions vs sandbox orchestration vs storage & updates
• Plugin extensibility: two distinct entry points (Function vs Tool) share the same backend
d. Technologies, frameworks, libraries
• Python 3.x, gVisor, Open WebUI plugin API
• GitHub Actions for CI, shell scripts for end-to-end tests
• Build tooling in Python for packaging
Detail
• all critical modules: plugin entries, sandbox core, storage & update components
• external dependencies explicitly (gVisor, Python runtime, GitHub Actions)