Open Interpreter (interpreter.chat) là tool open source cho phép LLM viết và chạy code thật trên máy. Khác Claude Code (tập trung dev workflow), Open Interpreter thiên về general automation: phân tích CSV, gọi API, generate report, sync file. Self-host trên VPS chạy 24/7 biến nó thành AI worker tự động.
Use case thực tế cho vibe coder VN: dạy LLM xử lý invoice PDF -> trích xuất data -> insert DB -> gửi email cho khách. Hoặc cron scrape giá vàng mỗi 15 phút -> post lên Telegram channel. Một lần setup, chạy 24/7 không cần can thiệp.
Bài này hướng dẫn cài Open Interpreter trên Cloud VPS 4GB Ubuntu 24.04, sandbox bằng Docker, expose REST API, ví dụ workflow thực tế.
1. Cài Open Interpreter (server mode)
sudo apt updatesudo apt install -y python3.11 python3-pip python3-venv # Tạo venvpython3 -m venv /opt/oi-envsource /opt/oi-env/bin/activate pip install open-interpreter interpreter --version# 0.4.x2. Cấu hình LLM provider
# Anthropic Claudeexport ANTHROPIC_API_KEY=sk-ant-xxxinterpreter --model claude-3-5-sonnet-20241022 # OpenAIexport OPENAI_API_KEY=sk-xxxinterpreter --model gpt-4o # Ollama local LLM (offline, miễn phí token)ollama serve &interpreter --model ollama/llama3.1:8b --api_base http://localhost:11434Ollama phù hợp cho VPS 4GB+ chạy llama3.1:8b. Local LLM không charge API, latency thấp, privacy cao.
3. Test command đầu tiên
interpreter > Đếm số file trong thư mục /var/log # Open Interpreter sẽ:# 1. Phân tích yêu cầu# 2. Generate command: ls /var/log | wc -l# 3. Xin permission user (auto_run=False mặc định)# 4. Chạy command, parse output# 5. Trả về số count đẹp4. Sandbox bằng Docker bắt buộc
# DockerfileFROM python:3.11-slim RUN apt-get update && apt-get install -y curl git nodejs npm tmux jq && rm -rf /var/lib/apt/lists/* RUN pip install open-interpreter fastapi uvicorn RUN useradd -m -s /bin/bash aiUSER aiWORKDIR /home/ai EXPOSE 8000CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "8000"]# Build và chạydocker build -t open-interpreter . docker run -d --name oi --cap-drop ALL --security-opt no-new-privileges --read-only --tmpfs /tmp:rw,noexec,nosuid,size=500m -v /var/oi-workspace:/home/ai/workspace -p 127.0.0.1:8000:8000 -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY --restart unless-stopped open-interpreterCap-drop ALL, read-only root, non-root user - container không thể escalate, không thể đè file hệ thống. Workspace mount riêng để persist data.
5. Expose REST API với FastAPI
# /home/ai/server.pyfrom fastapi import FastAPI, HTTPExceptionfrom pydantic import BaseModelfrom interpreter import interpreterimport os app = FastAPI()interpreter.llm.model = "claude-3-5-sonnet-20241022"interpreter.llm.api_key = os.getenv("ANTHROPIC_API_KEY")interpreter.auto_run = True # auto chạy không hỏiinterpreter.os = True API_TOKEN = os.getenv("API_TOKEN", "change-me") class TaskRequest(BaseModel): task: str context: dict = {} @app.post("/task")async def run_task(req: TaskRequest, authorization: str = ""): if authorization != f"Bearer {API_TOKEN}": raise HTTPException(403, "Unauthorized") interpreter.reset() result = [] for chunk in interpreter.chat(req.task, stream=False, display=False): result.append(chunk) return {"status": "ok", "messages": result} @app.get("/health")async def health(): return {"status": "running"}6. Caddy reverse proxy + SSL
# /etc/caddy/Caddyfileai.yourdomain.com { reverse_proxy 127.0.0.1:8000 @api { path /task /health } handle @api { reverse_proxy 127.0.0.1:8000 }} sudo systemctl reload caddy7. Test API từ external
curl -X POST https://ai.yourdomain.com/task -H "Authorization: Bearer mytoken123" -H "Content-Type: application/json" -d '{ "task": "Đếm số file .log trong workspace, group theo extension, return JSON" }' # Response:# {# "status": "ok",# "messages": [...# "Tôi đã tìm thấy 47 file .log",# {"counts": {".log": 47}}# ]# }8. Workflow thực tế: scrape giá vàng -> Telegram
# cron-task.sh - chạy mỗi 15 phút#!/bin/bashTASK="Truy cập sjc.com.vn, lấy giá vàng SJC 9999 mua/bán hôm nay,format thành message: 'SJC: mua X tr - bán Y tr (lúc HH:MM)',gửi POST tới Telegram bot API với token $TG_TOKEN, chat_id $TG_CHAT" curl -X POST https://ai.yourdomain.com/task -H "Authorization: Bearer mytoken123" -H "Content-Type: application/json" -d "{"task": "$TASK"}" # Crontabecho '*/15 * * * * /opt/cron-task.sh' >> /etc/crontabOpen Interpreter tự viết Python scrape SJC, parse HTML, format message, gửi Telegram. Một lần config, chạy 24/7. Khi UI SJC đổi, LLM tự adapt.
9. Use case automation khác
- Invoice PDF processing: đọc PDF, OCR, extract data, insert MySQL, gửi email.
- Log analysis: tail nginx log mỗi giờ, summarize lỗi 500, alert Slack.
- Data sync: pull data từ Google Sheets -> transform -> push PostgreSQL.
- Image processing: watch folder, auto resize + watermark, upload S3.
- Code review bot: webhook GitHub PR, AI review diff, comment suggest.
10. Resource limit và rate limit
# Docker compose với limitservices: oi: image: open-interpreter cpus: 1.5 mem_limit: 1g pids_limit: 100 restart: unless-stopped environment: - MAX_TASK_PER_HOUR=60 # Trong server.py thêm rate limitfrom slowapi import Limiterfrom slowapi.util import get_remote_address limiter = Limiter(key_func=get_remote_address)app.state.limiter = limiter @app.post("/task")@limiter.limit("60/hour")async def run_task(...): ...11. Monitor và audit log
# Log mọi task vào fileimport logginglogging.basicConfig( filename='/var/log/oi-tasks.log', level=logging.INFO, format='%(asctime)s - %(message)s') @app.post("/task")async def run_task(req: TaskRequest, ...): logging.info(f"TASK: {req.task[:200]}") result = ... logging.info(f"RESULT: {str(result)[:500]}") return result # Tail log realtimetail -f /var/log/oi-tasks.log12. Cost và LLM model recommendation
| Model | Cost/1M token | Speed | Code quality |
|---|---|---|---|
| Claude Sonnet 4.6 | ~3-15 USD | 50t/s | Rất cao |
| GPT-4o | ~5-15 USD | 80t/s | Cao |
| Gemini 2.0 Flash | ~0.5-3 USD | 150t/s | Tốt |
| Ollama llama3.1:8b | 0 (chỉ điện VPS) | 20-40t/s | Trung bình |
Khuyến nghị: Gemini Flash cho automation cost-sensitive, Claude Sonnet cho task code phức tạp. Ollama nếu cần offline 100%.
FAQ
Open Interpreter có an toàn để chạy 24/7 không?
An toàn nếu sandbox đúng cách: Docker với cap-drop ALL, non-root user, read-only root, network restricted. KHÔNG bao giờ chạy native trên host với root privileges.
Có thể giới hạn loại command LLM được chạy không?
Có. Set custom_instructions trong interpreter.system_message: NEVER run rm -rf, DROP TABLE, format. Hoặc dùng AppArmor profile chặn syscall nhất định.
VPS RAM tối thiểu cho Open Interpreter là bao nhiêu?
2GB nếu dùng API LLM (Claude, GPT). 8GB+ nếu chạy Ollama local LLM cùng. RAM ăn nhiều nhất khi LLM generate code Python phức tạp ~500MB.
Có nên expose API public không?
Không nên public. Always require API token + IP whitelist + rate limit. Nên chỉ truy cập từ internal network hoặc VPN.
Khác biệt với n8n/Zapier?
n8n có node visual GUI, predefined integration. Open Interpreter dùng natural language, LLM tự nghĩ code. Mạnh hơn cho task ad-hoc không có node sẵn. Tích hợp được cả 2: n8n trigger -> webhook -> Open Interpreter.
LLM có nhớ context giữa các task không?
Default mỗi task reset context. Có thể save conversation history trong DB và load lại nếu cần stateful workflow. Cẩn thận context dài tốn nhiều token.
