sphinxcontrib-coderun
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.
How it works
- 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.
Install
pip install sphinxcontrib-coderun
Configuration
In 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).
Usage
Replace .. literalinclude:: with .. coderun:: wherever you want a Run button:
.. coderun:: cprogs/hello.c
:language: c
Override the sandbox or URL for a specific snippet:
.. coderun:: examples/hello.py
:language: python
:sandbox: python
:url: https://codapi.example.com
All standard literalinclude options work — :lines:, :linenos:,
:emphasize-lines:, etc.
Self-hosting codeapi
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/codapi
For production deployment (Kubernetes, TLS, rate limiting) see the codeapi documentation.
Point coderun_url at the public URL of your server and you're done.
Development
Project structure
sphinxcontrib-coderun/
├── pyproject.toml
├── LICENSE
├── README.md
└── sphinxcontrib/
├── __init__.py # namespace package
└── coderun/
├── __init__.py # directive + Sphinx setup()
└── static/
└── coderun.css # Run button styling
Local setup
git clone https://github.com/uthcode/sphinxcontrib-coderun
cd sphinxcontrib-coderun
pip install -e .
To test against a Sphinx project, add to its conf.py:
extensions = [..., "sphinxcontrib.coderun"]
coderun_url = "http://localhost:1313" # local codeapi for dev
coderun_sandbox = "gcc"
Building a distribution
pip install build twine
python -m build
# produces dist/sphinxcontrib_coderun-X.Y.Z.tar.gz
# dist/sphinxcontrib_coderun-X.Y.Z-py3-none-any.whl
Validate before uploading:
python -m twine check dist/*
Publishing to PyPI
Create an API token at pypi.org/manage/account/token scoped to this project, then:
python -m twine upload dist/*
# Username: __token__
# Password: pypi-AgEI...
Releasing a new version
- Bump
versioninpyproject.toml. - Delete
dist/. - Run
python -m build. - Run
python -m twine upload dist/*.
License
MIT
Release files for sphinxcontrib-coderun 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sphinxcontrib_coderun-0.1.1.tar.gz | 5.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sphinxcontrib_coderun-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.5 kB
Release files / sphinxcontrib_coderun-0.1.1.tar.gz
| Download URL | sphinxcontrib_coderun-0.1.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e0b73d9f8b94499c8daa7896bb5281d3f7c6208b2ca7e83fc085e0c23a1aa7a
|
|
BLAKE2b-256 checksum How to use checksums |
7d25d201f348882ee7bf5bc2ad54aedf4d83dcc77e2477dc9ff3374ea930bc81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 25, 2026.
Transparency logRelease files / sphinxcontrib_coderun-0.1.1-py3-none-any.whl
| Download URL | sphinxcontrib_coderun-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e80f60c3b5bdb70a379fa79b6ee13b19b8986d9f6e44654de320766b0f79150b
|
|
BLAKE2b-256 checksum How to use checksums |
e3552845c429aa9d2dcfa47c07a78834ea06242e6efbd4ae477284cbb8f76841
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 25, 2026.
Transparency log