interpretthis
Run untrusted or LLM-generated Python inside a sandbox — from Python.
interpretthis evaluates a Python AST under resource limits and an allowlisted
language surface. It is not CPython in a subprocess and not a container: the
interpreter is written in Rust and simply has no filesystem, network, or process
access to give away. Capabilities reach the script only through tools you
inject.
pip install interpretthis
Why
You want a model to write Python that transforms data, scores records, or
orchestrates your tools — without handing it a real Python process. exec() in a
try block is not a sandbox. This is the evaluator: you own the tools, the
limits, and what happens to the result.
Quick start
from interpretthis import Interpreter
def double(n: int) -> int:
return n * 2
interp = Interpreter(tools={"double": double})
result = interp.execute("answer = double(n=x)\nprint(answer)", {"x": 21})
print(result.stdout) # '42\n'
print(interp.get_variable("answer")) # 42
Failure is data, not an exception. execute returns an ExecutionResult
carrying stdout and error, because a script that prints three lines and
then raises has told you something useful in both halves — and that pair is
exactly what you feed back to a model:
result = interp.execute("print('working...')\nresult = 1 / 0")
result.ok # False
result.stdout # 'working...\n'
result.error # PythonException('ZeroDivisionError: division by zero ...')
result.check() # raises, if you would rather
Tools
A tool is any callable — sync or async. The script calls it by name; arguments
arrive as keywords.
import aiohttp
async def fetch(url: str) -> str:
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
return await response.text()
interp = Interpreter(tools={"fetch": fetch})
interp.execute("page = fetch(url='https://example.com')")
Coroutine tools work from the blocking execute() too — the interpreter runs
them on a background event loop it starts on first use. Inside async code, use
execute_async instead, which schedules tool coroutines on your loop so they
may await objects bound to it (an aiohttp session, an asyncio.Lock):
result = await interp.execute_async("page = fetch(url='https://example.com')")
Tools that are safe to overlap can say so, and the interpreter will run them concurrently:
from interpretthis import Tool
interp = Interpreter(tools={"fetch": Tool(fetch, parallelizable=True)})
A tool that raises becomes a catchable Exception inside the script, and a
ToolError for you if the script does not catch it.
Limits
from interpretthis import Config
interp = Interpreter(config=Config(
max_operations=1_000_000,
max_memory_bytes=64 * 1024 * 1024,
max_execution_time=5.0, # seconds
max_recursion_depth=100,
))
Exceeding one stops the script with a LimitExceededError — with whatever it
printed before then still in stdout.
Resumable state
Variables and classes persist across execute calls on one interpreter, and can
be checkpointed:
blob = interp.export_state() # bytes; sign or encrypt them yourself
later = Interpreter()
later.import_state(blob)
later.execute("counter = counter + 1")
What it is not
- Not full CPython. A large subset, deliberately chosen. See
CONFORMANCE.md. - Tools are trusted. A tool with side effects extends the trust boundary by exactly as much as it does. That is the point, and it is your call.
async/awaitinside the script is not supported. Await aroundexecute, not within it.
Security boundary:
THREAT_MODEL.md.
Types
The package ships py.typed and is checked under mypy --strict.
Licence
MIT OR Apache-2.0, at your option.
Binary wheels statically link malachite (LGPL-3.0-only), reached transitively
via the Python parser. See the bundled NOTICE.
Metadata
Release files for interpretthis 0.4.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 | Provenance | Actions |
|---|---|---|---|---|
| interpretthis-0.4.1.tar.gz | 912.0 kB | With provenance | Details for interpretthis-0.4.1.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| interpretthis-0.4.1-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for interpretthis-0.4.1-cp311-abi3-win_amd64.whl |
| interpretthis-0.4.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64 | Details for interpretthis-0.4.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| interpretthis-0.4.1-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for interpretthis-0.4.1-cp311-abi3-macosx_11_0_arm64.whl |
| interpretthis-0.4.1-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details for interpretthis-0.4.1-cp311-abi3-macosx_10_12_x86_64.whl |
Total release size: 27.7 MB
Release files / interpretthis-0.4.1.tar.gz
| Download URL | interpretthis-0.4.1.tar.gz |
|---|---|
| Size | 912.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8802e57bcca7bcf8e2197246c1970f54799f1021892781d5ac36742ae354813d
|
|
BLAKE2b-256 checksum How to use checksums |
d0e505185a901fc55040b610b42da8e1b2e984c3513bf1b7cfa23503015258ea
|
| 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 Jul 17, 2026.
Transparency logRelease files / interpretthis-0.4.1-cp311-abi3-win_amd64.whl
| Download URL | interpretthis-0.4.1-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 6.8 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
060df40afd77042d0b7b259f6358b847452b3c0f90101ac98c3986039f4393d5
|
|
BLAKE2b-256 checksum How to use checksums |
fd22a810969b74fbc70a14a5ce757f9373135d2b270a9cfb6584ab34fb2d8ac1
|
| 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 Jul 17, 2026.
Transparency logRelease files / interpretthis-0.4.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | interpretthis-0.4.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 7.0 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
743a30fa68f5e224158710f5988e92ba2d70ad3cbf4a6112a98363ddcef0ee53
|
|
BLAKE2b-256 checksum How to use checksums |
449a1e6770baec2048b24315d06407f58138755a02fc839cc5682cb3841c4611
|
| 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 Jul 17, 2026.
Transparency logRelease files / interpretthis-0.4.1-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | interpretthis-0.4.1-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 6.5 MB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a8ece9f4a504d2df6965fec56f75aec9d798c464734ca2a6b4d671cdd849fb6f
|
|
BLAKE2b-256 checksum How to use checksums |
a24c5362647519791942922a27820715d11bf98c5ad05b37019f2aba3f5c29c7
|
| 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 Jul 17, 2026.
Transparency logRelease files / interpretthis-0.4.1-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | interpretthis-0.4.1-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 6.5 MB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
2946374eeb078fad71a4c314df72c5205bf49bd26c69c9d71de5d2eaa536f652
|
|
BLAKE2b-256 checksum How to use checksums |
97a4dd48a0d87b99b9da4441113db4ed83d1e1c049df5855a51a69c6ce17b77a
|
| 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 Jul 17, 2026.
Transparency logSecurity for interpretthis 0.4.1
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.
Full provenance
All 5 files in this release have been uploaded with provenance metadata.
Attestation for interpretthis-0.4.1.tar.gz
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 Jul 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.