Self-hosted sandboxes for AI agents and reinforcement-learning rollouts: Firecracker microVMs, containers and full VMs behind one API, with memory-preserving fork and an E2B-compatible gateway.
OpenDsec runs many isolated sandboxes on your own Linux machines, from a single host to a cluster, for reinforcement-learning rollouts and agents that execute code. It ships a Python SDK, a CLI, and an API compatible with E2B's SDKs, under AGPL-3.0.
A microVM can be paused into a memory snapshot, restored, or forked while running. Copies on the same node share memory pages; a fork on another node pulls the snapshot from the source. A sandbox can also be packed back into a new image from its changes.
import asyncio
from opendsec import DSecClient, DSecRunArgs
async def main():
async with DSecClient() as client:
sb = await client.run_sandbox(DSecRunArgs(
backend="microvm", image="root/py:3.12",
cpu_cores_limit=1, memory_limit_mb=1024,
network_rules={"pypi": True})) # outbound denied unless allowed
try:
print((await sb.run_shell("python3 -c 'print(6*7)'")).stdout)
forks = await sb.fork(count=4) # four copies, memory included
for f in forks:
await f.stop()
finally:
await sb.stop()
asyncio.run(main())
These are measurements of OpenDsec on its own machines, not figures from the paper. Method and conditions are in docs/SPEC.md.
| Measurement | Value |
|---|---|
| microVM cold start | ~0.1 s |
| Restore from memory snapshot | ~55 ms |
| Resume after pause | ~50 ms |
| Source VM stall during fork | ~10 ms |
| Burst of microVMs, one 384-thread node | 5,120 |
| Burst of containers, two nodes | 8,192, no failures |
Where the paper leaves a decision open, docs/SPEC.md marks each point as either taken from the paper, with its section, or the project's own decision.
One Linux x86_64 machine with systemd and cgroup v2 is enough. MicroVMs need /dev/kvm; without it the script sets up containers only.
git clone https://github.com/Kernflux/opendsec
cd opendsec
deploy/quickstart.sh # or --no-microvm for containers only
Existing E2B programs need only three environment variables pointed at the gateway:
export E2B_API_URL=https://sandbox.internal:7400
export E2B_SANDBOX_URL=https://sandbox.internal:7400
export E2B_API_KEY=dsk.…
The server and tools are AGPL-3.0. The client parts (the Python SDK, the Go client, and the API definitions) are Apache-2.0, so programs using OpenDsec are not bound by the AGPL.