Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ EXPOSE 8222
# Start the FastAPI application
# CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8002", "--workers", "1", "--no-access-log"]

RUN apt-get --fix-broken install

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The apt-get --fix-broken install command is removed. While it might seem like a cleanup, ensure that there are no broken packages that this command was intended to fix. If broken packages are expected, consider adding a comment explaining why this command is not needed or if the issue is handled elsewhere.

# Ensure Node.js, npm (and npx) are set up
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
RUN apt-get install -y nodejs
RUN apt-get update && apt-get install -y nodejs



Expand Down
46 changes: 42 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,41 @@ pip install -r examples/requirements.txt
You can now ask Claude to execute code, and it will run safely in the sandbox!
</details>

### Option 2: Python OpenAI Agents
### Option 2: Claude Code CLI

<details>
<summary>Use CodeRunner with Claude Code CLI for terminal-based AI assistance:</summary>

![Claude Code Demo](images/claude-code-demo.png)

**Quick Start:**

```bash
# 1. Install and start CodeRunner (one-time setup)
git clone https://github.com/instavm/coderunner.git
cd coderunner
sudo ./install.sh

# 2. Install the Claude Code plugin
claude plugin marketplace add github:BandarLabs/coderunner/instavm-coderunner-plugin
claude plugin install instavm-coderunner@instavm-plugins

# 3. Reconnect to MCP servers
/mcp
```

That's it! Claude Code now has access to all CodeRunner tools:
- **execute_python_code** - Run Python code in persistent Jupyter kernel
- **navigate_and_get_all_visible_text** - Web scraping with Playwright
- **list_skills** - List available skills (docx, xlsx, pptx, pdf, image processing, etc.)
- **get_skill_info** - Get documentation for specific skills
- **get_skill_file** - Read skill files and examples

**Learn more:** See [instavm-coderunner-plugin/README.md](instavm-coderunner-plugin/README.md) for detailed documentation.

</details>
Comment on lines +89 to +121

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The addition of the Claude Code CLI section is a good enhancement. However, ensure that the instructions are clear and easy to follow for users with varying levels of technical expertise. Consider adding more context or explanations for each step, especially for those unfamiliar with command-line interfaces or plugin installations.


### Option 3: Python OpenAI Agents
<details>
<summary>Use CodeRunner with OpenAI's Python agents library:</summary>

Expand All @@ -106,7 +140,7 @@ pip install -r examples/requirements.txt
Enter prompts like "write python code to generate 100 prime numbers" and watch it execute safely in the sandbox!
</details>

### Option 3: Gemini-CLI
### Option 4: Gemini-CLI
[Gemini CLI](https://github.com/google-gemini/gemini-cli) is recently launched by Google.

<details>
Expand All @@ -132,7 +166,7 @@ pip install -r examples/requirements.txt
![gemini2](images/gemini2.png)


### Option 4: Kiro by Amazon
### Option 5: Kiro by Amazon
[Kiro](https://kiro.dev/blog/introducing-kiro/) is recently launched by Amazon.

<details>
Expand Down Expand Up @@ -161,7 +195,7 @@ pip install -r examples/requirements.txt
</details>


### Option 5: Coderunner-UI (Offline AI Workspace)
### Option 6: Coderunner-UI (Offline AI Workspace)
[Coderunner-UI](https://github.com/instavm/coderunner-ui) is our own offline AI workspace tool designed for full privacy and local processing.

<details>
Expand Down Expand Up @@ -256,6 +290,10 @@ The `examples/` directory contains:
- `openai-agents` - Example OpenAI agents integration
- `claude-desktop` - Example Claude Desktop integration

## Building Container Image Tutorial

https://github.com/apple/container/blob/main/docs/tutorial.md

## Contributing

We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ else
echo "✅ macOS system detected."
fi

download_url="https://github.com/apple/container/releases/download/0.5.0/container-0.5.0-installer-signed.pkg"
download_url="https://github.com/apple/container/releases/download/0.8.0/container-installer-signed.pkg"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The download URL for the container installer is updated. Verify that the new version (0.8.0) is compatible with all existing configurations and that it has been thoroughly tested. Also, consider adding a comment explaining why the version was updated.


# Check if container is installed and display its version
if command -v container &> /dev/null
Expand Down
13 changes: 13 additions & 0 deletions instavm-coderunner-plugin/.claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "instavm-plugins",
"owner": {
"name": "InstaVM"
},
"plugins": [
{
"name": "instavm-coderunner",
"source": ".",
"description": "Execute Python code in a local sandboxed Apple container with fast kernel pool performance"
}
]
}
10 changes: 10 additions & 0 deletions instavm-coderunner-plugin/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "instavm-coderunner",
"version": "1.0.0",
"description": "Execute Python code in a sandboxed Apple container via local CodeRunner MCP server",
"author": {
"name": "InstaVM"
},
"homepage": "https://github.com/instavm/coderunner",
"license": "MIT"
}
8 changes: 8 additions & 0 deletions instavm-coderunner-plugin/.mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"mcpServers": {
"instavm-coderunner": {
"command": "python3",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/mcp-proxy.py"]
}
}
}
258 changes: 258 additions & 0 deletions instavm-coderunner-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
# InstaVM CodeRunner Plugin for Claude Code

This plugin enables Claude Code to execute Python code in a local sandboxed Apple container using [InstaVM CodeRunner](https://github.com/instavm/coderunner) via the Model Context Protocol (MCP).

## Quick Start

```bash
# 1. Install and start CodeRunner (one-time setup)
git clone https://github.com/instavm/coderunner.git
cd coderunner
sudo ./install.sh

# 2. Install the Claude Code plugin
claude plugin marketplace add github:BandarLabs/coderunner/instavm-coderunner-plugin
claude plugin install instavm-coderunner@instavm-plugins

# 3. Reconnect to MCP servers
/mcp
```

That's it! Claude Code now has access to all CodeRunner tools.

## Installation

### Prerequisites

**IMPORTANT:** You must have CodeRunner installed and running **before** installing this plugin.

#### Install CodeRunner

```bash
git clone https://github.com/instavm/coderunner.git
cd coderunner
sudo ./install.sh
```

This will:
- Install Apple's container runtime (version 0.8.0+)
- Pull the `instavm/coderunner` container image
- Start the CodeRunner MCP service at `http://coderunner.local:8222/mcp`

**Verify CodeRunner is running:**
```bash
curl http://coderunner.local:8222/execute -X POST -H "Content-Type: application/json" -d '{"code":"print(\"test\")"}'
```

### Install via GitHub URL (Recommended)

```bash
# Add the InstaVM marketplace from GitHub
claude plugin marketplace add github:BandarLabs/coderunner/instavm-coderunner-plugin

# Install the plugin
claude plugin install instavm-coderunner@instavm-plugins
```

### Option 2: Install from Local Path

If you've cloned the repository locally:

```bash
# Add local marketplace
claude plugin marketplace add /path/to/coderunner/instavm-coderunner-plugin

# Install the plugin
claude plugin install instavm-coderunner@instavm-plugins
```

## Usage

Once installed, Claude will have access to the `execute_python_code` tool from CodeRunner. You can ask Claude to execute Python code:

```
Please execute this Python code:
```python
import math
print(f"The square root of 16 is {math.sqrt(16)}")
```
```

Or simply:
```
Execute this code: print("Hello from CodeRunner!")
```

## Available Tools

The plugin exposes the following MCP tools from CodeRunner:

- **execute_python_code**: Execute Python code in a persistent Jupyter kernel with full stdout/stderr capture
- **navigate_and_get_all_visible_text**: Web scraping using Playwright - navigate to URLs and extract visible text
- **list_skills**: List all available skills (both public and user-added) in CodeRunner
- **get_skill_info**: Get documentation for a specific skill (reads SKILL.md)
- **get_skill_file**: Read any file from a skill's directory (e.g., EXAMPLES.md, API.md)

## Features

- **Local Execution**: Code runs on your machine in a sandboxed container
- **No Cloud Uploads**: Process files locally without uploading to cloud services
- **Fast Performance**: Pre-warmed Jupyter kernel pool (2-5 kernels) for quick execution
- **Full Output**: Returns stdout, stderr, execution time, and CPU time
- **Security**: Runs in Apple container isolation
- **MCP Integration**: Uses standard Model Context Protocol for tool communication

## Configuration

By default, the plugin connects to `http://coderunner.local:8222/mcp` via a stdio proxy. To customize the URL, set the `MCP_URL` environment variable in `.mcp.json`:

```json
{
"mcpServers": {
"instavm-coderunner": {
"command": "python3",
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/mcp-proxy.py"],
"env": {
"MCP_URL": "http://your-custom-url:8222/mcp"
}
}
}
}
```

## Example Output

```python
# Code:
print("Hello from CodeRunner!")
import time
time.sleep(0.1)
for i in range(3):
print(f"Count: {i}")
```

**Result:**
```
Hello from CodeRunner!
Count: 0
Count: 1
Count: 2

Execution time: 0.156s
```

## Requirements

- macOS 26.0+ (recommended) for Apple Container support
- Python 3.10+
- CodeRunner installed and running
- Claude Code with MCP plugin support

## Troubleshooting

### Plugin shows "failed" status

**Most common cause:** CodeRunner container is not running.

**Solution:**
```bash
# Check if CodeRunner is running
curl http://coderunner.local:8222/execute -X POST -H "Content-Type: application/json" -d '{"code":"print(\"test\")"}'

# If not running, restart it:
cd /path/to/coderunner
sudo ./install.sh
```

### "Invalid Host header" error

The CodeRunner MCP server is running but rejecting requests. This means the container needs to be restarted with proper hostname configuration.

**Solution:**
```bash
# Stop existing containers
sudo pkill -f container
container system start

# Restart CodeRunner container
container run --name coderunner --detach --rm --cpus 8 --memory 4g \
--volume "$HOME/.coderunner/assets/skills/user:/app/uploads/skills/user" \
--volume "$HOME/.coderunner/outputs:/app/uploads/outputs" \
instavm/coderunner
```

### MCP connection errors

1. **Check MCP logs:**
```bash
cat ~/Library/Caches/claude-cli-nodejs/-Users-manish-coderunner-instavm-coderunner-plugin/mcp-logs-*/latest/*.jsonl
```

2. **Test MCP endpoint manually:**
```bash
curl -H "Host: coderunner.local:8222" http://coderunner.local:8222/mcp \
-X POST -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05"}}'
```

3. **Verify proxy script:**
```bash
cd /path/to/instavm-coderunner-plugin
python3 scripts/mcp-proxy.py
# Then send: {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05"}}
```

## How It Works

This plugin uses Claude Code's MCP server integration to connect to the local CodeRunner instance:

1. The `.mcp.json` file defines the MCP server connection
2. Python proxy script bridges stdio MCP to HTTP endpoint
3. Tools from CodeRunner are automatically discovered and made available
4. When you ask Claude to execute code, it uses the `execute_python_code` tool
5. Results are returned via the MCP protocol

## Publishing to GitHub Marketplace

This plugin is published on GitHub and can be installed directly via the GitHub URL. Here's how to publish updates:

### 1. Commit and Push Changes

```bash
cd instavm-coderunner-plugin
git add .
git commit -m "Update plugin"
git push origin main
```

### 2. Users Install from GitHub

Users can install the plugin directly from GitHub:

```bash
# Add the InstaVM marketplace
claude plugin marketplace add github:BandarLabs/coderunner/instavm-coderunner-plugin

# Install the plugin
claude plugin install instavm-coderunner@instavm-plugins
```

That's it! Claude Code will automatically pull the plugin files from GitHub.

## Repository Structure

```
coderunner/
└── instavm-coderunner-plugin/ # Plugin directory
├── .claude-plugin/
│ ├── marketplace.json # Marketplace metadata
│ └── plugin.json # Plugin manifest
├── scripts/
│ └── mcp-proxy.py # stdio-to-HTTP MCP proxy
├── .mcp.json # MCP server configuration
└── README.md # This file
```

## License

MIT
Loading