Conda Executor
About
Executes Python code within isolated Conda environments, enabling secure and flexible code generation and execution for tasks like data analysis and algorithm testing.
Details
- Author
- bazinga012
- Repository
- bazinga012/mcp_code_executor
- GitHub stars
- 52
- Downloads
- 561
- License
- MIT License
- Categories
- Developer Tools, Productivity, Design, File Management, AI, Automation, Frontend, Project Management, Security
Jump to
- Execute Python code from LLM prompts
- Support for incremental code generation to overcome token limitations
- Run code within a specified environment (Conda, virtualenv, or UV virtualenv)
- Install dependencies when needed
- Check if packages are already installed
- Dynamically configure the environment at runtime
- Configurable code storage directory
Setting up with Highlight
This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:
- Download and install Highlight from highlightai.com/download
- Navigate to the plugins tab and select "Add Custom Plugin"
-
Configure the plugin with the settings below
Plugin Name
Conda ExecutorCommand (node, npx, python, etc.)nodeArguments-
Argument 1
/path/to/mcp_code_executor/build/index.js
Environment-
ENV_TYPE
conda -
CONDA_ENV_NAME
your-conda-env -
CODE_STORAGE_DIR
/path/to/code/storage
Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.
-
Argument 1
- Enable "Start Automatically" if you want the plugin to start when Highlight launches
From the repository
Once configured, the MCP Code Executor will allow LLMs to execute Python code by generating a file in the specified CODE_STORAGE_DIR and running it within the configured environment.
LLMs can generate and execute code by referencing this MCP server in their prompts.
- For Conda:
- ENV_TYPE: Set to conda
- CONDA_ENV_NAME: Name of the Conda environment to use
- For Standard Virtualenv:
- ENV_TYPE: Set to venv
- VENV_PATH: Path to the virtualenv directory
- For UV Virtualenv:
- ENV_TYPE: Set to venv-uv
- UV_VENV_PATH: Path to the UV virtualenv directory
Installs Python packages in the environment.
{
"name": "install_dependencies",
"arguments": {
"packages": ["numpy", "pandas", "matplotlib"]
}
}
Checks if packages are already installed in the environment.
{
"name": "check_installed_packages",
"arguments": {
"packages": ["numpy", "pandas", "non_existent_package"]
}
}
Dynamically changes the environment configuration.
{
"name": "configure_environment",
"arguments": {
"type": "conda",
"conda_name": "new_env_name"
}
}
Gets the current environment configuration.
{
"name": "get_environment_config",
"arguments": {}
}
execute_code
Executes Python code in the configured environment. Best for short code snippets. Parameters: code (string), filename (string)
install_dependencies
Installs Python packages in the environment. Parameters: packages (array of strings)
check_installed_packages
Checks if packages are already installed in the environment. Parameters: packages (array of strings)
configure_environment
Dynamically changes the environment configuration. Parameters: type (string), conda_name (string)
get_environment_config
Gets the current environment configuration. Parameters: none
initialize_code_file
Creates a new Python file with initial content. Use this as the first step for longer code that may exceed token limits. Parameters: content (string), filename (string)
append_to_code_file
Appends content to an existing Python code file. Use this to add more code to a file created with initialize_code_file. Parameters: file_path (string), content (string)
execute_code_file
Executes an existing Python file. Use this as the final step after building up code with initialize_code_file and append_to_code_file. Parameters: file_path (string)
read_code_file
Reads the content of an existing Python code file. Use this to verify the current state of a file before appending more content or executing it. Parameters: file_path (string)
The MCP Code Executor provides the following tools to LLMs:
Claude Desktop / Cursor
Paste into your MCP client config file to install this server.
{
"mcpServers": {
"conda executor": {
"env": {
"ENV_TYPE": "conda",
"CONDA_ENV_NAME": "your-conda-env",
"CODE_STORAGE_DIR": "/path/to/code/storage"
},
"args": [
"/path/to/mcp_code_executor/build/index.js"
],
"command": "node"
}
}
}
Linux
{
"env": {
"ENV_TYPE": "conda",
"CONDA_ENV_NAME": "your-conda-env",
"CODE_STORAGE_DIR": "/path/to/code/storage"
},
"args": [
"/path/to/mcp_code_executor/build/index.js"
],
"command": "node"
}
Macos
{
"env": {
"ENV_TYPE": "conda",
"CONDA_ENV_NAME": "your-conda-env",
"CODE_STORAGE_DIR": "/path/to/code/storage"
},
"args": [
"/path/to/mcp_code_executor/build/index.js"
],
"command": "node"
}
Windows
{
"env": {
"ENV_TYPE": "conda",
"CONDA_ENV_NAME": "your-conda-env",
"CODE_STORAGE_DIR": "/path/to/code/storage"
},
"args": [
"/c",
"node",
"/path/to/mcp_code_executor/build/index.js"
],
"command": "cmd"
}
MCP Code Executor
The MCP Code Executor is an MCP server that allows LLMs to execute Python code within a specified Python environment. This enables LLMs to run code with access to libraries and dependencies defined in the environment. It also supports incremental code generation for handling large code blocks that may exceed token limits.
<a href="https://glama.ai/mcp/servers/45ix8xode3"></a>
Features
- Execute Python code from LLM prompts
- Support for incremental code generation to overcome token limitations
- Run code within a specified environment (Conda, virtualenv, or UV virtualenv)
- Install dependencies when needed
- Check if packages are already installed
- Dynamically configure the environment at runtime
- Configurable code storage directory
Prerequisites
- Node.js installed
- One of the following:
- Conda installed with desired Conda environment created
- Python virtualenv
- UV virtualenv
Setup
1. Clone this repository:
git clone https://github.com/bazinga012/mcp_code_executor.git
2. Navigate to the project directory:
``bash
cd mcp_code_executor
3. Install the Node.js dependencies:
bash
npm install
4. Build the project:
bashnpm run build
Configuration
To configure the MCP Code Executor server, add the following to your MCP servers configuration file:
Using Node.js
json{
"mcpServers": {
"mcp-code-executor": {
"command": "node",
"args": [
"/path/to/mcp_code_executor/build/index.js"
],
"env": {
"CODE_STORAGE_DIR": "/path/to/code/storage",
"ENV_TYPE": "conda",
"CONDA_ENV_NAME": "your-conda-env"
}
}
}
}
Using Docker
json{
"mcpServers": {
"mcp-code-executor": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp-code-executor"
]
}
}
}
json { "name": "execute_code", "arguments": { "code": "import numpy as np\nprint(np.random.rand(3,3))", "filename": "matrix_gen" } }CODE_STORAGE_DIR
> Note: The Dockerfile has been tested with the venv-uv environment type only. Other environment types may require additional configuration.Environment Variables
Required Variables
-: Directory where the generated code will be storedENV_TYPEEnvironment Type (choose one setup)
- For Conda: -: Set toconda-CONDA_ENV_NAME: Name of the Conda environment to useENV_TYPE- For Standard Virtualenv:
-: Set tovenvVENV_PATH
-: Path to the virtualenv directoryENV_TYPE- For UV Virtualenv:
-: Set tovenv-uvUV_VENV_PATH
-: Path to the UV virtualenv directoryexecute_codeAvailable Tools
The MCP Code Executor provides the following tools to LLMs:
1.
Executes Python code in the configured environment. Best for short code snippets.
json { "name": "install_dependencies", "arguments": { "packages": ["numpy", "pandas", "matplotlib"] } }install_dependencies2.
Installs Python packages in the environment.
json { "name": "check_installed_packages", "arguments": { "packages": ["numpy", "pandas", "non_existent_package"] } }check_installed_packages3.
Checks if packages are already installed in the environment.
json { "name": "configure_environment", "arguments": { "type": "conda", "conda_name": "new_env_name" } }configure_environment4.
Dynamically changes the environment configuration.
json { "name": "get_environment_config", "arguments": {} }get_environment_config5.
Gets the current environment configuration.
json { "name": "initialize_code_file", "arguments": { "content": "def main():\n print('Hello, world!')\n\nif __name__ == '__main__':\n main()", "filename": "my_script" } }initialize_code_file6.
Creates a new Python file with initial content. Use this as the first step for longer code that may exceed token limits.
json { "name": "append_to_code_file", "arguments": { "file_path": "/path/to/code/storage/my_script_abc123.py", "content": "\ndef another_function():\n print('This was appended to the file')\n" } }append_to_code_file7.
Appends content to an existing Python code file. Use this to add more code to a file created with initialize_code_file.
json { "name": "execute_code_file", "arguments": { "file_path": "/path/to/code/storage/my_script_abc123.py" } }execute_code_file8.
Executes an existing Python file. Use this as the final step after building up code with initialize_code_file and append_to_code_file.
json { "name": "read_code_file", "arguments": { "file_path": "/path/to/code/storage/my_script_abc123.py" } } `read_code_file9.
Reads the content of an existing Python code file. Use this to verify the current state of a file before appending more content or executing it.
Usage
Once configured, the MCP Code Executor will allow LLMs to execute Python code by generating a file in the specified
CODE_STORAGE_DIR and running it within the configured environment.
LLMs can generate and execute code by referencing this MCP server in their prompts.
Handling Large Code Blocks
For larger code blocks that might exceed LLM token limits, use the incremental code generation approach:
1. Initialize a file with the basic structure using
initialize_code_file
2. Add more code in subsequent calls using append_to_code_file
3. Verify the file content if needed using read_code_file
4. Execute the complete code using execute_code_file`
This approach allows LLMs to write complex, multi-part code without running into token limitations.
Backward Compatibility
This package maintains backward compatibility with earlier versions. Users of previous versions who only specified a Conda environment will continue to work without any changes to their configuration.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
License
This project is licensed under the MIT License.
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.





