Skip to content

Commit 5321019

Browse files
authored
Touchup Documentation
Also removed unused build param
2 parents a8fe13b + 8c62a04 commit 5321019

3 files changed

Lines changed: 17 additions & 115 deletions

File tree

CLAUDE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ uv sync --locked
1717
```bash
1818
# Start the API server (uses HOST/PORT env vars, defaults to 0.0.0.0:8000)
1919
code-interpreter-api
20+
```
2021

2122
### Code Quality Checks
2223
```bash
@@ -100,6 +101,6 @@ There are two main kinds of tests:
100101
#### E2E Tests
101102

102103
- Under the `code-interpreter/tests/e2e` directory
103-
- Requires the code-interpreter service to be running. Usually as a docker container.
104+
- Requires the code-interpreter service to be running. Usually as a Docker container.
104105
- After making changes, if you want to run these tests make sure to (1) stop existing containers, \
105106
(2) build new images, and (3) run the new containers.

README.md

Lines changed: 13 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
# Code Interpreter
22

3-
**NOTE:** Code Interpreter is currently in Alpha. Be careful with production usage.
3+
A secure service for executing untrusted Python code in isolated Docker containers. This service provides a REST API for running code with strict resource limits, timeout controls, and file handling capabilities.
44

5-
A secure, FastAPI-based service for executing Python code in isolated Docker containers. This service provides a REST API for running untrusted Python code with strict resource limits, timeout controls, and file handling capabilities.
5+
Everything runs locally and the execution environment comes pre-packaged with a list of common Python libraries.
66

7-
The goal of the project is to be the easiest, lightest weight way to add secure python execution to your AI agent.
7+
This project aims to be the easiest, lightest weight way to add secure Python execution to your AI agent.
88

9-
Powers the Code Interpreter in [Onyx](https://github.com/onyx-dot-app/onyx). Checkout the implementation
10-
[here]() as a good reference for using this in your app.
9+
## How it works
10+
11+
The security first architecture and an overview of the implementation can be found [here](https://github.com/onyx-dot-app/code-interpreter/blob/main/HOW_IT_WORKS.md).
1112

1213
## Quick Start
1314

14-
### Docker Deployment
15+
> Note: This repo powers the Code Interpreter feature in [Onyx](https://github.com/onyx-dot-app/onyx).
16+
Check out the implementation [here](https://github.com/onyx-dot-app/onyx/tree/main/backend/onyx/tools/tool_implementations/python) as a reference for using it in your app.
1517

16-
The code-interpreter service needs access to Docker to run code in isolated containers. There are two deployment modes:
18+
### Docker Deployment
1719

1820
#### Option 1: Docker-out-of-Docker (Recommended)
1921

20-
This is the recommended approach for most use cases. It shares the host's Docker daemon for better performance:
22+
This is the recommended approach for most use cases. This shares the host's Docker daemon for better performance to spin up and manage the ephemeral code execution containers.
2123

2224
```bash
2325
docker run --rm -it \
@@ -36,7 +38,7 @@ docker run --rm -it \
3638

3739
#### Option 2: Docker-in-Docker
3840

39-
Use this when you need complete isolation or can't access the host Docker socket:
41+
Use this when you need complete isolation or can't access the host Docker socket. This runs a separate Docker daemon in a container to manage the code execution containers.
4042

4143
```bash
4244
docker run --rm -it \
@@ -57,71 +59,9 @@ docker run --rm -it \
5759
- Subsequent runs will reuse the cached image (instant startup)
5860
- The server will not accept requests until the executor image is available
5961

60-
#### Building from Source
61-
62-
```bash
63-
# Standard build (executor image pulled at runtime)
64-
docker build -t code-interpreter -f code-interpreter/Dockerfile .
65-
66-
# Build with pre-loaded executor image for instant DinD startup
67-
./build-preloaded.sh code-interpreter:preloaded
68-
```
69-
70-
**Build arguments:**
71-
- `SKIP_NESTED_DOCKER=1` - Skip installing Docker entirely (only for Docker-out-of-Docker mode)
72-
- `PYTHON_EXECUTOR_DOCKER_IMAGE=custom/image` - Use a custom executor image
73-
74-
#### Pre-loaded Images for Faster Startup
75-
76-
For production or offline environments, you can build an image with the executor pre-embedded:
77-
78-
```bash
79-
# Build pre-loaded image (includes executor, ~1GB larger but instant DinD startup)
80-
./build-preloaded.sh code-interpreter:preloaded
81-
82-
# Run with instant startup (no pulling needed)
83-
docker run --rm -it \
84-
--privileged \
85-
-p 8000:8000 \
86-
code-interpreter:preloaded
87-
```
88-
89-
This is ideal for:
90-
- Production deployments (predictable startup times)
91-
- Air-gapped/offline environments
92-
- CI/CD pipelines
93-
- Any scenario where you want instant DinD readiness
94-
95-
### Local Deployment
96-
97-
#### Prerequisites
98-
99-
- Python 3.11
100-
- Docker (for execution isolation)
101-
- [uv](https://github.com/astral-sh/uv) package manager (recommended)
102-
103-
#### Running the Service
104-
105-
```bash
106-
# Clone the repository
107-
git clone https://github.com/onyx-dot-app/code-interpreter.git
108-
cd code-interpreter
62+
### Kubernetes Deployment
10963

110-
# Activate an virtual environment
111-
python -m venv .venv
112-
source .venv/bin/activate
113-
114-
# Install dependencies
115-
uv sync --locked
116-
```
117-
118-
```bash
119-
# Start the API server (defaults to 0.0.0.0:8000)
120-
code-interpreter-api
121-
122-
# Or specify host/port via environment variables
123-
HOST=127.0.0.1 PORT=8080 code-interpreter-api
124-
```
64+
See [here](https://github.com/onyx-dot-app/code-interpreter/blob/main/kubernetes/code-interpreter/README.md) for Helm and K8s deployment instructions
12565

12666
## API Usage
12767

@@ -214,46 +154,6 @@ Configure the service via environment variables:
214154
- `MAX_FILE_SIZE_MB`: Maximum file upload size (default: `10`)
215155
- `FILE_STORAGE_DIR`: Directory for file storage (default: `/tmp/code-interpreter-files`)
216156

217-
## Development
218-
219-
### Code Quality
220-
221-
```bash
222-
# Type checking (must pass strict mypy)
223-
mypy .
224-
225-
# Linting
226-
ruff check .
227-
228-
# Formatting
229-
ruff format .
230-
231-
# Run all pre-commit hooks
232-
pre-commit run --all-files
233-
```
234-
235-
### Testing
236-
237-
```bash
238-
# Run integration tests
239-
pytest tests/integration_tests -q
240-
241-
# Run a specific test
242-
pytest tests/integration_tests/test_file.py::test_function_name -v
243-
```
244-
245-
## Architecture
246-
247-
The service follows a layered architecture:
248-
249-
- **API Layer** (`app/api/`): FastAPI routes and request handling
250-
- **Service Layer** (`app/services/`): Business logic and execution backends
251-
- **Models** (`app/models/`): Pydantic schemas for request/response validation
252-
- **Configuration** (`app/core/`): Environment-based settings management
253-
254-
Execution is handled through an abstraction layer supporting multiple backends:
255-
- **Docker Executor**: Runs code in isolated Docker containers (recommended)
256-
257157
## Security
258158

259159
- All code execution happens in isolated environments

code-interpreter/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Dockerfile for the FastAPI application service (distinct from executor image)
22
FROM python:3.11-slim
33

4+
# This can be toggled off to build a Kubernetes only image
5+
# Without Docker-in-Docker and Docker-out-of-Docker support, this cannot work with Docker Compose
46
ARG SKIP_NESTED_DOCKER=0
5-
ARG SKIP_IMAGE_PRELOAD=0
67

78
WORKDIR /app
89

0 commit comments

Comments
 (0)