# Open Interpreter

**Open Interpreter** 让语言模型通过自然语言聊天界面在您的机器上运行代码、浏览网页并编辑文件。拥有 57K+ GitHub 星， 它是 ChatGPT 的 Code Interpreter 的领先开源替代方案 —— 但没有沙箱限制。

{% hint style="success" %}
所有示例都可以在通过以下方式租用的 GPU 服务器上运行 [CLORE.AI 市场](https://clore.ai/marketplace).
{% endhint %}

***

## 什么是 Open Interpreter？

Open Interpreter 将 AI 编码助手的能力直接带到您的终端。无需在 ChatGPT 和 shell 之间来回复制粘贴，您可以自然地对话，模型会实时执行代码：

* **运行 Python、JS、shell、R、AppleScript** — 直接在您的服务器上
* **浏览网页** — 获取页面、填写表单、提取数据
* **编辑文件** — 创建、修改并管理磁盘上的任意文件
* **持久状态** — 变量、导入和结果在消息之间保留
* **多种 LLM 后端** — OpenAI、Anthropic、本地模型（通过 Ollama/LlamaCpp）

{% hint style="info" %}
Open Interpreter 为想要对整个计算环境进行对话式操作的开发者和研究人员而设计。在 Clore.ai GPU 服务器上，您将获得一台功能强大的机器，具有完整的互联网访问且没有执行限制。
{% endhint %}

***

## 服务器要求

| 组件       | 最低要求          | 推荐配置                        |
| -------- | ------------- | --------------------------- |
| GPU      | 任何（提供 CPU 模式） | 本地 LLM 推荐显卡：RTX 3090 / A100 |
| 显存（VRAM） | —             | 本地 13B 模型需要 24 GB+          |
| 内存（RAM）  | 8 GB          | 16 GB+                      |
| CPU      | 4 个内核         | 8 个以上内核                     |
| 存储       | 20 GB         | 50 GB+                      |
| 操作系统     | Ubuntu 20.04+ | Ubuntu 22.04                |
| Python   | 3.10+         | 3.11                        |
| 网络       | 需要            | 用于网页浏览的高速网络                 |

***

## 端口

| 端口   | 服务                   | 说明                   |
| ---- | -------------------- | -------------------- |
| 22   | SSH                  | 终端访问，支持用于 Web UI 的隧道 |
| 8000 | Open Interpreter 服务器 | REST API & 可选 Web UI |

***

## 使用 Docker 快速开始

Open Interpreter 没有官方的 Docker 镜像，所以我们构建了一个干净的镜像。此方法可在任何 Clore.ai 服务器上为您提供可重现的、隔离的环境。

### Dockerfile

```dockerfile
FROM python:3.11-slim

# 系统依赖
RUN apt-get update && apt-get install -y \
    git \
    curl \
    wget \
    build-essential \
    nodejs \
    npm \
    chromium \
    chromium-driver \
    && rm -rf /var/lib/apt/lists/*

# 安装带全部扩展的 Open Interpreter
RUN pip install --no-cache-dir \
    open-interpreter \
    'open-interpreter[local]' \
    playwright \
    jupyter

# 安装 Playwright 浏览器
RUN playwright install chromium

WORKDIR /workspace

# 暴露服务器端口
EXPOSE 8000

# 默认：交互式终端
CMD ["interpreter"]
```

### 构建并运行

```bash
# 构建镜像
docker build -t open-interpreter:latest .

# 以交互模式运行（终端聊天）
docker run -it --rm \
  -e OPENAI_API_KEY=sk-... \
  -v $(pwd)/workspace:/workspace \
  open-interpreter:latest

# 作为 REST API 服务器运行
docker run -d \
  --name open-interpreter \
  -p 8000:8000 \
  -e OPENAI_API_KEY=sk-... \
  -v $(pwd)/workspace:/workspace \
  open-interpreter:latest \
  interpreter --server --port 8000 --host 0.0.0.0
```

***

## 在 Clore.ai（裸金属）上的安装

如果您更愿意直接在 Clore.ai 服务器上运行而不使用 Docker：

### 步骤 1 — 租用服务器

1. 前往 [Clore.ai 市场](https://clore.ai/marketplace)
2. 筛选条件 **内存 ≥ 16 GB**, **GPU** （可选但对本地模型有用）
3. 选择一台带有 **PyTorch** 或 **Ubuntu** 基础镜像
4. 打开 **SSH 端口 22** 并可选地 **8000** 在您的订单中

### 步骤 2 — 通过 SSH 连接

```bash
ssh root@<server-ip> -p <ssh-port>
```

### 第 3 步 — 安装依赖项

```bash
# 更新系统
apt-get update && apt-get upgrade -y

# 安装 Python 3.11
apt-get install -y python3.11 python3.11-venv python3.11-pip nodejs npm curl

# 创建虚拟环境
python3.11 -m venv /opt/open-interpreter
source /opt/open-interpreter/bin/activate
```

### 第 4 步 — 安装 Open Interpreter

```bash
# 基本安装
pip install open-interpreter

# 支持本地 LLM（Ollama、LlamaCpp）
pip install 'open-interpreter[local]'

# 支持浏览器/网页
pip install playwright
playwright install chromium
```

### 第 5 步 — 配置 API 密钥

```bash
# 设置环境变量（添加到 ~/.bashrc 以持久生效）
export OPENAI_API_KEY=sk-your-key-here
export ANTHROPIC_API_KEY=sk-ant-your-key-here

# 或使用 .env 文件
cat > /workspace/.env << 'EOF'
OPENAI_API_KEY=sk-your-key-here
ANTHROPIC_API_KEY=sk-ant-your-key-here
EOF
```

### 第 6 步 — 首次运行

```bash
# 激活环境
source /opt/open-interpreter/bin/activate

# 启动交互式聊天
interpreter

# 或使用特定模型
interpreter --model gpt-4o
interpreter --model claude-3-5-sonnet-20241022
```

***

## 使用本地 LLM（无需 API 密钥）

Open Interpreter 在 Clore.ai GPU 服务器上的一项关键功能是可以完全运行本地模型：

### 选项 A：Ollama 后端

```bash
# 安装 Ollama
curl -fsSL https://ollama.ai/install.sh | sh

# 拉取一个支持代码的模型
ollama pull codellama:13b
ollama pull deepseek-coder:6.7b
ollama pull mistral:7b

# 使用 Ollama 运行 Open Interpreter
interpreter --model ollama/codellama:13b
```

### 选项 B：LlamaCpp 后端

```bash
# 安装带 CUDA 支持的 llama-cpp-python
pip install 'llama-cpp-python[server]' --extra-index-url https://jllllll.github.io/llama-cpp-python-cuBLAS-wheels/AVX2/cu121

# 下载 GGUF 模型
wget https://huggingface.co/TheBloke/CodeLlama-13B-GGUF/resolve/main/codellama-13b.Q4_K_M.gguf

# 使用本地模型运行
interpreter --local --model /path/to/codellama-13b.Q4_K_M.gguf
```

***

## 作为服务器运行（REST API）

Open Interpreter 0.2+ 包含一个内置的 HTTP 服务器以供程序化访问：

```bash
# 启动服务器
interpreter --server --port 8000 --host 0.0.0.0

# 在另一个终端或客户端中发送请求：
curl -X POST http://<server-ip>:8000/run \
  -H "Content-Type: application/json" \
  -d '{"language": "python", "code": "import os; print(os.listdir(\\\".\\\"))"}'

# 聊天端点
curl -X POST http://<server-ip>:8000/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "列出 /workspace 中所有 Python 文件并统计代码行数"}'
```

### 用于本地访问的 SSH 隧道

如果端口 8000 未公开暴露，请使用 SSH 隧道：

```bash
# 在您的本地机器上
ssh -L 8000:localhost:8000 root@<server-ip> -p <ssh-port> -N
# 然后打开 http://localhost:8000
```

***

## 实用示例

### 示例 1：数据分析流水线

```
用户：下载 MNIST 数据集，训练一个简单的 CNN，并绘制准确率曲线。将图保存为 mnist_results.png

Open Interpreter：好的！我会逐步完成……
[实时执行 Python 代码]
```

```python
# Open Interpreter 生成并运行：
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np

(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
# ... 训练模型、绘制结果、保存 PNG
```

### 示例 2：网页抓取

```
用户：抓取今天排名前 10 的热门 GitHub 仓库，并将它们以包含名称、star 数和描述的 CSV 保存。
```

### 示例 3：文件管理

```
用户：查找 /var/log 中所有超过 7 天的 .log 文件，并将它们压缩为 /backup/logs-$(date).tar.gz 的 tar 包
```

### 示例 4：系统监控脚本

```
用户：为我写一个 Python 脚本，每 5 秒监测一次 GPU 内存使用情况，若超过 90% 则发出警报。将其在后台运行。
```

***

## 配置文件

创建 `~/.interpreter/config.yaml` 以设置默认值：

```yaml
model: gpt-4o
temperature: 0
system_message: |
  您是在 Clore.ai GPU 服务器上运行的有用 AI 助手。
  始终优先考虑高效、可投入生产的代码。
  将重要输出保存到 /workspace/。
safe_mode: false
auto_run: true
verbose: false
```

***

## 使用 systemd 运行（持久服务）

```ini
# /etc/systemd/system/open-interpreter.service
[Unit]
Description=Open Interpreter Server
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/workspace
Environment=OPENAI_API_KEY=sk-your-key
ExecStart=/opt/open-interpreter/bin/interpreter --server --port 8000 --host 0.0.0.0
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target
```

```bash
systemctl daemon-reload
systemctl enable open-interpreter
systemctl start open-interpreter
systemctl status open-interpreter
```

***

## 故障排除

### `interpreter` 找不到命令

```bash
# 确保已激活虚拟环境
source /opt/open-interpreter/bin/activate

# 或全局安装
pip install open-interpreter

# 检查 PATH
which interpreter
echo $PATH
```

### 代码执行被阻止 / 安全模式

```bash
# 禁用安全模式（在受信任的服务器上谨慎使用）
interpreter --safe_mode false

# 或在 config.yaml 中：
# safe_mode: false
# auto_run: true
```

### Playwright / 浏览器错误

```bash
# 为 Chromium 安装系统依赖
apt-get install -y \
    libnss3 libatk1.0-0 libatk-bridge2.0-0 \
    libcups2 libxcomposite1 libxdamage1 \
    libxrandr2 libgbm1 libxkbcommon0

playwright install chromium
playwright install-deps
```

### 本地 LLM 内存不足

```bash
# 使用更小的量化模型
ollama pull codellama:7b  # 代替 13b

# 或减少上下文窗口
interpreter --model ollama/codellama:7b --context_window 4096
```

### 端口 8000 连接被拒绝

```bash
# 检查服务器是否在运行
ss -tlnp | grep 8000

# 检查防火墙
ufw allow 8000/tcp

# 重启服务
systemctl restart open-interpreter
```

### API 速率限制

```bash
# 切换到 Anthropic Claude 以获得更高的限制
export ANTHROPIC_API_KEY=sk-ant-...
interpreter --model claude-3-5-sonnet-20241022

# 或使用本地模型以完全避免 API 限制
interpreter --model ollama/codellama:13b
```

***

## 安全注意事项

{% hint style="warning" %}
Open Interpreter 会直接在您的服务器上执行代码。始终：

* 在生产环境中请在 Docker 容器或虚拟机中运行
* 未经身份验证不要将端口 8000 公开暴露
* 对于远程访问使用 SSH 隧道
* 在启用之前审核代码 `auto_run: true` 针对不受信任的输入
  {% endhint %}

***

## Clore.ai 的 GPU 建议

Open Interpreter 本身很轻量 —— GPU 需求取决于您作为后端运行的 **本地模型** 。

| GPU       | 显存（VRAM） | Clore.ai 价格 | 本地模型推荐                                                   |
| --------- | -------- | ----------- | -------------------------------------------------------- |
| RTX 3090  | 24 GB    | \~$0.12/小时  | CodeLlama 13B Q8、Llama 3 8B、Mistral 7B —— 良好的编码质量        |
| RTX 4090  | 24 GB    | \~$0.70/小时  | CodeLlama 34B Q4、DeepSeek Coder 33B Q4 —— 接近 GPT-4 的编码质量 |
| A100 40GB | 40 GB    | \~$1.20/小时  | Llama 3 70B Q4 —— 生产级自主编码代理                              |
| 仅 CPU     | —        | ≈$0.02/小时   | 通过 OpenAI/Anthropic API 使用任何模型 —— 无需本地 GPU               |

{% hint style="info" %}
**如果您使用 OpenAI/Anthropic API：** 您只需要一个 CPU 实例（≈$0.02/小时）—— 因为推理在云端运行，GPU 无关紧要。仅在运行 **本地模型** 时才选择 GPU 实例以避免按 token 的 API 成本。

**最佳本地模型配置：** RTX 3090 + Ollama 运行 `codellama:13b` 可为您提供一个完全自主、保护隐私的编码代理，无需 API 成本，费用约为 \~$0.12/小时。
{% endhint %}

***

## 有用的链接

* **GitHub**: <https://github.com/OpenInterpreter/open-interpreter> ⭐ 57K+
* **文档**: <https://docs.openinterpreter.com>
* **Discord**: <https://discord.gg/Hvz9Axh84z>
* **Clore.ai 市场**: <https://clore.ai/marketplace>
* **Ollama 模型**: <https://ollama.ai/library>
* **HuggingFace GGUF 模型**: <https://huggingface.co/TheBloke>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-zh/ai-ping-tai-yu-zhi-neng-ti/open-interpreter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
