Capsule Python Adapter
Execute Python and JavaScript code securely inside Capsule sandboxes from your Python applications.
Installation
pip install capsule-run-adapter
Usage
Execute Python Code
from capsule_adapter import run_python
result = await run_python("""
print("Hello from Python!")
x = 5 + 3
x * 2
""")
print(result) # "Hello from Python!\n16"
Execute JavaScript Code
from capsule_adapter import run_javascript
result = await run_javascript("""
console.log("Hello from JavaScript!");
const x = 5 + 3;
x * 2;
""")
print(result) # "Hello from JavaScript!\n16"
Preload Sandboxes (Optional)
The first execution of a sandbox has a cold start (~1 second). You can preload sandboxes to warm them up for faster subsequent executions (~10ms):
import asyncio
from capsule_adapter import load_sandboxes, run_python
async def main():
# Preload sandboxes
await load_sandboxes()
# Or preload individually
# await load_python_sandbox() # Warm up Python only
# await load_javascript_sandbox() # Warm up JavaScript only
# Fast execution
result = await run_python('print("Fast!")')
print(result)
asyncio.run(main())
Sessions (Persistent State)
Use Session to run code across multiple calls while preserving state. Each session gets an isolated workspace directory that is automatically cleaned up when the session ends.
from capsule_adapter import Session
async with Session() as s:
await s.run("x = 1")
result = await s.run("x += 1; x")
print(result) # 2
JavaScript sessions work the same way:
async with Session("javascript") as s:
await s.run("x = 1")
result = await s.run("x += 1; x")
print(result) # 2
Import Files
Copy a file or directory from your filesystem into the session workspace. The sandbox code can then access it at the destination path under workspace/.
async with Session() as s:
# Import a single file
await s.import_file("./notes.txt", "notes.txt")
result = await s.run("""
with open("workspace/notes.txt") as f:
content = f.read()
content
""")
Export Files
Export file from the session workspace to your filesystem.
async with Session() as s:
await s.import_file("./notes.txt", "notes.txt")
# ... do some work ...
await s.export_file("notes.txt", "./exported_notes.txt")
Delete Files
Remove a file from the session workspace:
async with Session() as s:
await s.import_file("./notes.txt", "notes.txt")
# ... do some work ...
await s.delete_file("notes.txt")
Reset State
Clear the session's variable state without touching workspace files:
async with Session() as s:
await s.run("x = 42")
await s.reset()
result = await s.run("x") # raises NameError
How It Works
The adapter compiles Python and JavaScript sandboxes into WebAssembly modules during the build step. When you call run_python() or run_javascript(), the adapter invokes these pre-built sandboxes using Capsule's runner with the code you provide.
Learn more about Capsule.
Metadata
Release files for capsule-run-adapter 0.3.5
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 | |
|---|---|---|---|---|
| capsule_run_adapter-0.3.5.tar.gz | 11.7 MB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| capsule_run_adapter-0.3.5-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 23.4 MB
Release files / capsule_run_adapter-0.3.5.tar.gz
| Download URL | capsule_run_adapter-0.3.5.tar.gz |
|---|---|
| Size | 11.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cfb2bc3d192c5ac945c2f24e3d6e59217813ecda801baa22fb1d3eab5c5fbf38
|
|
BLAKE2b-256 checksum How to use checksums |
b15e774b1c84c63174570d0fa9ceb47ae63119350e5bc136978702ea5691907a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / capsule_run_adapter-0.3.5-py2.py3-none-any.whl
| Download URL | capsule_run_adapter-0.3.5-py2.py3-none-any.whl |
|---|---|
| Size | 11.7 MB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
f29f9a22e91dafd7927357403337a147ad78e4d89d0dac87cbc020494fc9c612
|
|
BLAKE2b-256 checksum How to use checksums |
50de8c420678895d76dc954dec2d5f084a973bb46dcde19c0f245128694142ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for capsule-run-adapter 0.3.5
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.