A Sphinx extension that adds an interactive Run button to code files in your documentation. Powered by a self-hosted codeapi instance — you bring your own server, this extension wires it into Sphinx.
- You self-host a codeapi server (supports C, Python, Go, Rust, and many more).
- You add
.. coderun::directives to your.rstfiles. - When a reader clicks Run, the code is sent to your codeapi server, executed in an isolated sandbox, and the output appears inline on the page.
Nothing is shared with third-party services — all execution happens on your own infrastructure.
pip install sphinxcontrib-coderunIn your conf.py:
extensions = [..., "sphinxcontrib.coderun"]
# URL of your self-hosted codeapi instance
coderun_url = "https://codapi.example.com"
# Default sandbox (matches a sandbox configured on your codeapi server)
coderun_sandbox = "gcc"Both settings can be overridden per-directive (see below).
Replace .. literalinclude:: with .. coderun:: wherever you want a Run button:
.. coderun:: cprogs/hello.c
:language: cOverride the sandbox or URL for a specific snippet:
.. coderun:: examples/hello.py
:language: python
:sandbox: python
:url: https://codapi.example.comAll standard literalinclude options work — :lines:, :linenos:,
:emphasize-lines:, etc.
You need a running codeapi instance that the browser can reach. Quickstart:
# Pull the server and a sandbox image
docker pull nalgeon/codapi
docker pull codapi/gcc # or python, go, etc.
# Run the server
docker run -p 1313:1313 -v /path/to/config:/opt/codapi nalgeon/codapiFor production deployment (Kubernetes, TLS, rate limiting) see the codeapi documentation.
Point coderun_url at the public URL of your server and you're done.
MIT