CoolFace
Apppublic

ShajinJoseph/code-interpreter

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

Code Interpreter

LibreChat-compatible code execution backend. Self-hosted Python + bash sandbox using smolagents LocalPythonExecutor (AST-restricted, in-process — no Docker-in-Docker), wrapped in a FastAPI app that speaks the same HTTP contract as code.librechat.ai.

The image bundles the tooling Anthropic's Agent Skills need at runtime so /exec never pays a package-install cost:

  • LibreOffice (headless), poppler-utils, qpdf, ghostscript, tesseract-ocr, pandoc
  • Node.js 20 LTS with docx, pptxgenjs, pdf-lib, xlsx installed globally (NODE_PATH set, so require('docx') works from any cwd)
  • Python: python-docx, python-pptx, openpyxl, pandas, pypdf, pdfplumber, pdf2image, pypdfium2, reportlab, mammoth, markitdown[pptx], pytesseract, pillow, matplotlib, plus smolagents
⚠️ No authentication. Anyone who can reach this service can run arbitrary code in the container. Run behind a reverse proxy with auth, on a private HF Space, or otherwise restrict network access.

Endpoints

MethodPathPurpose
POST/execExecute Python (lang: "py") or bash (lang: "bash"), return stdout / stderr / generated files
POST/uploadSingle-file multipart upload
POST/upload/batchMulti-file multipart upload
GET/download/{session_id}/{file_id}Retrieve a stored file
GET/healthLiveness probe

Schema matches LibreChat's packages/agents CodeExecutor and api/server/services/Files/Code/crud.js:

jsonc
// POST /exec request
{ "lang": "py", "code": "print(1+1)", "session_id": "...", "files": [{"id": "...", "session_id": "...", "name": "..."}] }

// POST /exec response
{ "stdout": "...", "stderr": "...", "session_id": "...", "files": [{"id": "...", "name": "..."}] }

// POST /upload response
{ "message": "success", "storage_session_id": "...", "files": [{"fileId": "...", "filename": "..."}] }

Configuration

Env varDefaultNotes
DATA_DIR/mnt/data (in image)Persistent session storage root. Skills expect this path to exist and be writable.
EXEC_TIMEOUT_SECONDS300Per-call execution timeout. Tuned for LibreOffice rendering of complex docs.

Deploy to a Hugging Face Space

  1. 1.Create a new Space, SDK: Docker.
  2. 2.Push these files to the Space repo.
  3. 3.Point LibreChat's LIBRECHAT_CODE_BASEURL at https://<your-space>.hf.space. Restrict network access at the Space level (private Space, etc.) — the service ships with no auth of its own.

Local dev

bash
docker build -t code-interpreter .
docker run -p 7860:7860 code-interpreter
# in another shell:
python test_local.py

Security notes

LocalPythonExecutor is AST-restricted but not a hardened sandbox — the container itself is the trust boundary. Imports are unrestricted inside the container so the document skills work; if you need stricter isolation, swap the executor for DockerExecutor or E2BExecutor. There is no application- level authentication; do not expose the service to the open internet.