Exxec
Read the documentation! One async API to run code and shell commands locally, in Docker, over SSH, or in cloud sandboxes.
exxec gives every backend the same interface: execute Python/JavaScript/TypeScript code, run and stream shell commands, spawn long-running processes (optionally on a PTY), and read and write files through an fsspec filesystem. Switch from local execution to Docker or E2B by changing one argument.
Installation
pip install exxec
Cloud and container backends need their SDK, installed via extras:
pip install "exxec[docker]" # or e2b, daytona, modal, beam, vercel, ssh, ...
pip install "exxec[vt]" # terminal emulation for TerminalSession
Quickstart
import asyncio
from exxec import get_environment
async def main() -> None:
async with get_environment("local") as env:
# Run code: return a value from `main()` or assign `_result`
result = await env.execute("""
async def main():
return "Hello from exxec!"
""")
print(result.success, result.result) # True Hello from exxec!
# Run a shell command
cmd = await env.execute_command("echo hi")
print(cmd.exit_code, cmd.stdout) # 0 hi
# Stream a command's output line by line
async for line in env.execute_command_stream("echo a; echo b"):
print(line)
asyncio.run(main())
Swap "local" for "docker", "e2b", "modal", ... (with the matching extra installed and
credentials configured); the rest of the code stays the same.
Providers
| Provider | get_environment() name |
Extra | spawn() |
PTY |
|---|---|---|---|---|
Local machine (in-process or isolated=True subprocess) |
local |
none | yes | yes (not on Windows) |
Anthropic sandbox-runtime (srt CLI) |
srt |
none (needs srt) |
yes | yes (not on Windows) |
| Pyodide via Deno | pyodide |
none (needs deno) |
||
| Docker (testcontainers) | docker |
docker |
yes | yes |
| SSH | ssh |
ssh |
yes | yes |
| E2B | e2b |
e2b |
yes | yes |
| Daytona | daytona |
daytona |
yes | yes |
| Modal | modal |
modal |
yes | yes |
| Vercel Sandbox | vercel |
vercel |
yes | yes |
| Microsandbox | microsandbox |
microsandbox |
yes | yes |
| Beam | beam |
beam |
yes | |
| Cloudflare Sandbox (Workers HTTP API) | cloudflare |
cloudflare |
||
| HopX | hopx |
hopx |
PTY manager only | |
| Sprites (Fly.io) | sprites |
sprites |
PTY manager only |
The classes are importable directly as well (LocalExecutionEnvironment,
DockerExecutionEnvironment, E2bExecutionEnvironment, ...). get_environment() has typed
overloads, so your editor shows each provider's options. MockExecutionEnvironment is
available for tests.
Features
Code execution
execute() runs a snippet and returns an ExecutionResult with success, result,
duration, stdout, stderr, error and error_type. The snippet either defines
main() (sync or async), whose return value becomes result, or assigns _result:
result = await env.execute("import math\n_result = math.pi * 2")
if not result.success:
print(result.error_type, result.error)
stream_code() and stream_command() yield typed events (ProcessStartedEvent,
OutputEvent, ProcessCompletedEvent, ProcessErrorEvent); execute_stream() and
execute_command_stream() yield plain output lines.
Processes and terminals
spawn() starts a process and returns a ProcessHandle (output iterator, write, wait,
kill, resize). With pty=PtySize(...) the process runs on a pseudo-terminal.
TerminalSession (extra vt) adds an emulated screen, which lets you drive interactive programs:
from exxec import LocalExecutionEnvironment
from exxec.terminal import TerminalSession
async with (
LocalExecutionEnvironment() as env,
await TerminalSession.start(env, "python3", ["-q"]) as term,
):
await term.wait_for(">>>")
await term.send_line("6 * 7")
await term.wait_for("42")
print(term.text())
await term.send_keys("C-d")
env.process_manager manages background processes and env.get_pty_manager() manages PTY sessions.
Filesystem
env.get_fs() returns an async fsspec filesystem for the environment (local, Docker, SSH,
and most sandboxes); set_file_content() and get_file_content() are shortcuts.
Configuration models
exxec_config holds lightweight pydantic models for every provider, a discriminated union
(ExecutionEnvironmentConfig) for config files, and get_provider() to build the environment:
from exxec_config import DockerExecutionEnvironmentConfig
config = DockerExecutionEnvironmentConfig(image="python:3.13-slim", dependencies=["numpy"])
async with config.get_provider() as env:
...
Remote callables and PEP 723 scripts
create_remote_callable(func, DockerExecutionEnvironment) wraps a function so that each call
runs inside a fresh environment, with dependencies inferred from its module.
ExecutionEnvironment.execute_script() runs a script with PEP 723 inline metadata and installs
its declared dependencies.
Documentation
Full API reference: phil65.github.io/exxec
License
MIT
Metadata
Release files for exxec 0.9.2
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 |
|---|---|---|---|---|
| exxec-0.9.2.tar.gz | 116.8 kB | With provenance | Details for exxec-0.9.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| exxec-0.9.2-py3-none-any.whl | Python 3 | none | any | Details for exxec-0.9.2-py3-none-any.whl |
Total release size: 266.0 kB
Release files / exxec-0.9.2.tar.gz
| Download URL | exxec-0.9.2.tar.gz |
|---|---|
| Size | 116.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2e65f7a0e8552ab7d2057267e93829a3a603c3eb77274d7c71148b871ab7a6ff
|
|
BLAKE2b-256 checksum How to use checksums |
1daae7b6a97286d256cc9f791bd5f59c09fc31c4791d671c593654b27081585f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 22, 2026.
Transparency logRelease files / exxec-0.9.2-py3-none-any.whl
| Download URL | exxec-0.9.2-py3-none-any.whl |
|---|---|
| Size | 149.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6f35e33fab0ee888a8513a3e1f8f7bffaee4009dee99a5eccbb723d07b54c5aa
|
|
BLAKE2b-256 checksum How to use checksums |
27acd6442b21052e7e5b3583f6f2f57ae3f1bfe92a0634e8846fd8842e1fbe1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 22, 2026.
Transparency logSecurity for exxec 0.9.2
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
Both files in this release have been uploaded with provenance metadata.
Attestation for exxec-0.9.2.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 Nov 22, 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.