Sandboxed code execution capabilities for Open WebUI.
Uses gVisor for secure sandboxing, as ChatGPT does.
Open WebUI addons come in multiple types. For code execution, this repository contains both a code execution function and a code execution tool.
You can install both.
Code execution function | Code execution tool |
---|---|
Click button to run code block. | Grant the LLM the ability to run code by itself. |
The code execution function shows up as a button under LLM-generated messages. When you click it, the code in the code block of this message will execute. The output is shown in the UI, and is also available to the LLM for further querying.
First, set up Open WebUI for sandboxing.
Then, in Open WebUI:
- Go to
Workspace
→Functions
. - Click the
+
. - Input the following:
- Function name:
Run code
- Function description:
Run arbitrary code safely in a gVisor sandbox.
- Replace the code section with the contents of
open-webui/functions/run_code.py
.
- Function name:
- Click the
Save
button. - Activate both toggles on the function you just created.
Ask the model to generate code, then click the Run code
button under the message to run it.
See screenshot
The code execution tool grants the LLM the ability to run code by itself. This is similar to granting "Web search" access which lets the LLM search the Web by itself. If the LLM decides to use this tool, the tool's output is invisible to you but is available as information for the LLM.
First, set up Open WebUI for sandboxing.
Then, in Open WebUI:
- Go to
Workspace
→Tools
. - Click the
+
. - Input the following:
- Toolkit name:
Run code
- Toolkit description:
Run arbitrary code safely in a gVisor sandbox.
- Replace the code section with the contents of
open-webui/tools/run_code.py
.
- Toolkit name:
- Click the
Save
button.
The tool needs to be enabled on a per-model basis.
- Go to
Workspace
→Models
. - Click the pencil (✏️) icon on a model that supports tool calling.
- Under
Tools
, check theRun Code
checkbox. - Click
Save & Update
.
When prompting the model, activate the "Run code" toggle on the message box. Then write your prompt.