A FastAPI-based code interpreter service that provides code execution and file management capabilities. This service is compatible with the LibreChat Code Interpreter API specification.
Note
This project is mostly a proof of concept and is not intended to be used in production.
For production ready solution and to support the amazing work of LibreChat maintainers use the LibreChat Code Interpreter.
- Easy deployment with single docker compose file
- Code is executed in a isolated Docker container sandbox, custom images supported
- Supports file upload and download
- Supports concurrent code execution
- Supports Python and R languages (possibility to extend to other languages)
- RESTful API with OpenAPI documentation
code-interpreter-086.mp4
Run the project with docker compose using docker compose -f compose.prod.yml up
It's possible to overwrite the default environment variables defined in ./app/shared/config.py by creating a .env file in the root directory.
By default the project will create two directories in the root directory: ./config and ./uploads.
config directory will hold the sqlite database and temp uploaded files.
uploads directory will hold the files uploaded by the users. All files uploaded by the users will be, by default, deleted after 24 hours.
By default the API is unauthenticated. To require an API key, set API_KEY in the service environment (or .env):
API_KEY=<your-secret-key>When set, all /v1 endpoints require a matching x-api-key header and return 401 otherwise (/health stays open). LibreChat sends this header automatically using its LIBRECHAT_CODE_API_KEY value, so the two must match.
LibreChat is configured to use the code interpreter API by default.
To configure LibreChat to use the local code interpreter, set the following environment variables in LibreChat:
LIBRECHAT_CODE_API_KEY=<any-value-here> # must match the service's API_KEY if one is configured
LIBRECHAT_CODE_BASEURL=http(s)://host:port/v1/librechat # for local testing use to point to host IP http://host.docker.internal:8000/v1/librechat- Install dependencies using uv:
uv sync --all-extras
source .venv/bin/activate- Start the development server:
docker compose upThe API will be available at http://localhost:8000. The OpenAPI documentation can be accessed at http://localhost:8000/docs.
Most tests exercise code execution, which starts sandbox containers via the host Docker daemon. That requires:
- A reachable Docker socket — the app talks to Docker on the host, not inside its own filesystem.
- Correct
HOST_PATH— session files live at./uploadsinside the app, but sandbox bind mounts must use the host path (e.g./your/project/uploads/<session_id>). Compose setsHOST_PATH=$PWDfor this; running pytest with the wrong value causesbind source path does not existerrors.
The simplest way to satisfy both is to run tests in the same environment as the dev server:
docker compose up -d
docker compose exec code-interpreter uv run pytest tests -vTest logs are written to logs/test.log.
Alternative — run on the host (without docker compose exec):
uv sync --all-extras
uv run pytest tests -vThe first run may take longer while sandbox images (jupyter/scipy-notebook, jupyter/r-notebook, node:24-slim) are pulled.