Code Interpreter

Repository layout

Where everything lives and which component each directory becomes.

Top level

src/
config/sandbox.cfg
Dockerfile
openapi.yaml
src/
Dockerfile*
openapi.yml
build-packages.sh
javascript-packages.txt
docker-compose*.yml
PathBecomesLanguage
api/Sandbox runnerTypeScript (Bun)
service/API, worker, file server, tool call server, egress gatewayTypeScript (Node/Bun)
launcher/microVM launcherRust
docker/Sandbox and package-init imagesDockerfiles + shell
helm/codeapi/Kubernetes chartHelm
seccomp/, apparmor/Host-level hardening profilesJSON / AppArmor
docs/This documentation siteNext.js + Fumadocs
build-packages.shRuntime and package installerBash

service/src: the trusted tier

One codebase, several entry points. Which one runs is chosen by the Dockerfile target.

Entry points

FileComponent
api-server.tsThe public API (SERVICE_PORT, 3112)
worker-server.tsThe job worker (health on 3113)
file-server.tsFile server (3000)
tool-call-server.tsTool call server (3033)
egress-gateway.tsEgress gateway (3190)
local-api.ts, service-api.tsAPI variants for local and service modes

Security core

FileResponsibility
execution-manifest.tsSigning and verifying execution manifests.
execution-manifest-claims.tsThe claim shape.
egress-grant.tsMinting and parsing encrypted egress grants.
egress-ledger.tsRedis-backed grant ledger: budgets, revocation, counters.
egress-gateway-client.tsClient used by trusted components.
internal-service-auth.tsComponent-to-component shared-token auth.
session-key.tsDeriving the storage namespace from auth context.
execution-identity.tsResolving the principal and tenant.
auth/JWT verification, key loading, JWKS.
secure-startup.tsFail-fast configuration validation at boot.
tool-scope.ts, tool-input-signature.tsTool-call authorization.

Execution path

FileResponsibility
service/router.ts/exec, /upload, /download, /files routes.
service/programmatic-router.ts/exec/programmatic and its continuation handling.
queue.ts, workers.tsBullMQ queues and worker registration.
sandbox-dispatch.tsBuilds the signed request sent to the sandbox runner.
payload.tsAssembles the execution payload.
preamble.ts, preamble-bash.tsInjected tool-calling preambles.
matplotlib.py, matplotlib-async.pyTemplates wrapping plotting code.
session-persist.tsPersistent-session snapshot logic.
sandbox-egress.tsEgress helpers for the sandbox path.

Support

config.ts (environment parsing), metrics.ts (Prometheus), telemetry.ts (OpenTelemetry), logger.ts, middleware/limits.ts (rate limiting), http-limits.ts, lifecycle.ts (startup and graceful shutdown), redis-options.ts, types/, enum/.

api/src: the sandbox runner

FileResponsibility
index.tsEntry point.
api/v2.tsThe /api/v2 routes: execute, runtimes, health.
job.tsThe big one, the whole job lifecycle: staging, fetching, running, collecting, uploading.
nsjail.tsBuilds the NsJail invocation and the Kafel seccomp policy.
nsjail-setup-gate.tsSerialises sandbox setup, with a watchdog.
workspace-isolation.tsPer-job workspaces, UID pools, permissions, the reaper.
runtime.tsDiscovers installed runtimes from the packages volume.
execution-manifest.tsManifest verification (public key only).
execution-manifest-request.tsVerifying a request against its manifest.
egress.tsEgress grant header handling.
dependencies.tsValidating request-declared pip specs.
tool-call-socket-proxy.tsThe in-sandbox tool-call socket.
secure-startup.tsFail-fast startup checks.
safe-error.tsClassifying errors safe to return to callers.
validation.ts, walker.tsRequest validation and filesystem walking.
spec-guard.cA small native guard compiled into the image.

api/config/sandbox.cfg is the NsJail protobuf config: namespace flags, the mount table, UID/GID mapping, and default cgroup limits. Per-execution overrides are passed as CLI arguments by nsjail.ts.

launcher/: the microVM launcher

A single main.rs binding libkrun's C API through FFI:

krun_create_ctx() → krun_set_vm_config() → krun_set_root()
krun_add_virtiofs() → krun_set_port_map() → krun_set_exec()
krun_start_enter()

It also installs a seccomp filter of its own before entering the guest. Deliberately tiny: it runs adjacent to untrusted code, so there is little of it to get wrong. Built with opt-level = "s", LTO, and stripped.

Docker images

DockerfileProduces
service/Dockerfile (targets api, worker, production)API, worker, file server
service/Dockerfile.apiAPI only
service/Dockerfile.workerWorker only
service/Dockerfile.tool-call-serverTool call server
service/Dockerfile.egress-gatewayEgress gateway
api/DockerfileSandbox runner (includes NsJail, libkrun, the launcher)
docker/Dockerfile.package-initThe one-shot runtime installer
docker/Dockerfile.worker-sandboxCombined worker + sandbox

Where the docs live

  • docs/: this site (Next.js + Fumadocs). Content in docs/content/docs.
  • service/openapi.yml: the public API spec, rendered into the API reference.
  • api/openapi.yaml: the internal runner spec, rendered into the sandbox API reference.
  • helm/codeapi/README.md, apparmor/README.md, seccomp/README.md: component-level notes kept next to the code.

The two OpenAPI specs are the source of truth for their reference sections; the site regenerates those pages at build time, so editing the spec is how you edit those docs.

On this page