emberpool 0.1.0a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- emberpool-0.1.0a1/LICENSE +21 -0
- emberpool-0.1.0a1/PKG-INFO +234 -0
- emberpool-0.1.0a1/README.md +202 -0
- emberpool-0.1.0a1/pyproject.toml +72 -0
- emberpool-0.1.0a1/pyproject.toml.orig +62 -0
- emberpool-0.1.0a1/src/emberpool/__init__.py +10 -0
- emberpool-0.1.0a1/src/emberpool/_assets/__init__.py +7 -0
- emberpool-0.1.0a1/src/emberpool/_assets/ep-init +52 -0
- emberpool-0.1.0a1/src/emberpool/_assets/inittab +4 -0
- emberpool-0.1.0a1/src/emberpool/_firecracker.py +948 -0
- emberpool-0.1.0a1/src/emberpool/_jailer.py +304 -0
- emberpool-0.1.0a1/src/emberpool/_ledger.py +815 -0
- emberpool-0.1.0a1/src/emberpool/_names.py +272 -0
- emberpool-0.1.0a1/src/emberpool/_protocol.py +255 -0
- emberpool-0.1.0a1/src/emberpool/_resolver.py +436 -0
- emberpool-0.1.0a1/src/emberpool/_settings.py +317 -0
- emberpool-0.1.0a1/src/emberpool/_setup.py +897 -0
- emberpool-0.1.0a1/src/emberpool/_types.py +433 -0
- emberpool-0.1.0a1/src/emberpool/_wiring.py +365 -0
- emberpool-0.1.0a1/src/emberpool/cli.py +146 -0
- emberpool-0.1.0a1/src/emberpool/engine.py +123 -0
- emberpool-0.1.0a1/src/emberpool/exec_client.py +145 -0
- emberpool-0.1.0a1/src/emberpool/guest/_protocol.py +255 -0
- emberpool-0.1.0a1/src/emberpool/guest/agent.py +412 -0
- emberpool-0.1.0a1/src/emberpool/netpolicy.py +864 -0
- emberpool-0.1.0a1/src/emberpool/pool.py +668 -0
- emberpool-0.1.0a1/src/emberpool/py.typed +0 -0
- emberpool-0.1.0a1/src/emberpool/trace.py +780 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Samarjit Debnath
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: emberpool
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: Firecracker microVM sandboxes for AI agent code, with deny-by-default egress and a host-side audit trail that the sandboxed code cannot alter.
|
|
5
|
+
Keywords: sandbox,firecracker,microvm,ai-agents,llm,security
|
|
6
|
+
Author: Samarjit Debnath
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
10
|
+
Classifier: Framework :: AsyncIO
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
20
|
+
Classifier: Topic :: Security
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Dist: dnspython>=2.9.2
|
|
23
|
+
Requires-Dist: httpx>=0.29.0
|
|
24
|
+
Requires-Python: >=3.12
|
|
25
|
+
Project-URL: Homepage, https://github.com/SamarjitDebnath/emberpool
|
|
26
|
+
Project-URL: Documentation, https://github.com/SamarjitDebnath/emberpool/tree/main/docs
|
|
27
|
+
Project-URL: Source, https://github.com/SamarjitDebnath/emberpool
|
|
28
|
+
Project-URL: Issues, https://github.com/SamarjitDebnath/emberpool/issues
|
|
29
|
+
Project-URL: Changelog, https://github.com/SamarjitDebnath/emberpool/blob/main/CHANGELOG.md
|
|
30
|
+
Project-URL: Security, https://github.com/SamarjitDebnath/emberpool/security/policy
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# emberpool
|
|
34
|
+
|
|
35
|
+
Firecracker microVM sandboxes for AI agent code, with deny-by-default egress and a host-side audit trail that the sandboxed code cannot alter.
|
|
36
|
+
|
|
37
|
+
emberpool is a Python library that gives an AI agent a disposable Linux microVM for each piece of code it runs, and a host-recorded log of what that code tried to do over the network.
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from emberpool import SandboxPool
|
|
41
|
+
|
|
42
|
+
async with SandboxPool(size=4, network="allow:pypi.org,files.pythonhosted.org") as pool:
|
|
43
|
+
result = await pool.run(
|
|
44
|
+
"import socket; socket.create_connection(('pypi.org', 443)); print('reached pypi')",
|
|
45
|
+
timeout=60, # one deadline: waiting for a free VM plus the run itself
|
|
46
|
+
)
|
|
47
|
+
print(result.exit_code, result.stdout)
|
|
48
|
+
for event in result.trace: # DNS queries and connection verdicts, seen by the host
|
|
49
|
+
print(event)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
> **Status: pre-alpha (0.1.0a1).** v0.1 is implemented and runs end to end on an aarch64 development host under nested virtualization. It has not been run on bare metal, and the API may change in any 0.x minor release (see the [changelog](https://github.com/SamarjitDebnath/emberpool/blob/main/CHANGELOG.md)). Performance targets are unmeasured; timings from the nested-virtualization development VM are not benchmarks.
|
|
53
|
+
|
|
54
|
+
## Why
|
|
55
|
+
|
|
56
|
+
Agents run code they wrote a moment ago, and sometimes code someone tricked them into writing. emberpool is built around three ideas:
|
|
57
|
+
|
|
58
|
+
- **A real VM boundary.** Each run gets its own Firecracker microVM under KVM with its own guest kernel, launched through Firecracker's jailer. Untrusted code never shares the host kernel.
|
|
59
|
+
- **Speed from snapshots.** A template VM is booted once, with the in-guest agent running, and snapshotted. Sandboxes are restored from it and kept warm, so a run does not pay for a kernel boot. Each run starts a fresh `python3` process inside its VM, and every VM is destroyed after one run.
|
|
60
|
+
- **Evidence, not self-reporting.** Network policy and the trace live on the host. The sandbox cannot hide a DNS lookup or a connection attempt, because the guest is never asked.
|
|
61
|
+
|
|
62
|
+
## How it works
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
your agent ── await pool.run(code) ──▶ emberpool (host, Python, root)
|
|
66
|
+
│ restore from snapshot
|
|
67
|
+
▼
|
|
68
|
+
Firecracker microVM, jailed
|
|
69
|
+
own kernel · 1 vCPU · 512 MiB
|
|
70
|
+
agent on vsock · own netns
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
1. **Build once.** Boot a template VM, wait for the in-guest agent, snapshot memory and state.
|
|
74
|
+
2. **Restore many.** Each sandbox gets a fresh jail, a fresh scratch drive over a shared read-only root filesystem, and its own network namespace, then loads the snapshot.
|
|
75
|
+
3. **Run.** Code goes to the guest over vsock. A replacement VM is restored in the background.
|
|
76
|
+
4. **Tear down.** The VM is killed, its namespace deleted, and the host's trace returned with the result.
|
|
77
|
+
|
|
78
|
+
Networking is deny-by-default. When you allowlist domain names, emberpool's own DNS resolver answers only those names, and nftables on the host admits connections only to the addresses it returned. Every query and every verdict is logged.
|
|
79
|
+
|
|
80
|
+
## What you can trust in a `Result`
|
|
81
|
+
|
|
82
|
+
| Field | Source | Trust |
|
|
83
|
+
|---|---|---|
|
|
84
|
+
| `trace` | Host resolver and nftables | Complete; the guest cannot alter it |
|
|
85
|
+
| `timed_out` | Host | The host killed the VM |
|
|
86
|
+
| `error` | Host | `None` if the guest returned a result; `"timeout"` or `"agent"` otherwise |
|
|
87
|
+
| `file_changes` | Host reads the scratch drive (never mounts it) | Advisory; end state only |
|
|
88
|
+
| `stdout`, `stderr`, `exit_code` | Guest agent | Convenience; code in the sandbox can forge them |
|
|
89
|
+
|
|
90
|
+
## Requirements
|
|
91
|
+
|
|
92
|
+
Check these before installing:
|
|
93
|
+
|
|
94
|
+
- **Root.** v0.1 must run as root: the jailer and per-sandbox networking need it. Each Firecracker process still drops privileges inside its jail.
|
|
95
|
+
- **Linux with KVM** (`/dev/kvm`).
|
|
96
|
+
- **aarch64.** It is the only architecture verified so far; others may work but are untested.
|
|
97
|
+
|
|
98
|
+
The host also needs:
|
|
99
|
+
|
|
100
|
+
- Firecracker v1.18.0 and its jailer.
|
|
101
|
+
- A 6.1 guest kernel with device-tree VMGenID support, so restored clones get fresh randomness. See [setup](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/10-setup.md) for how to check.
|
|
102
|
+
- Python 3.12 or newer; [uv](https://docs.astral.sh/uv/) for working from a checkout.
|
|
103
|
+
- `iproute2`, `nftables`, `e2fsprogs` and `tar`. No Docker: `emberpool setup` builds the guest image itself.
|
|
104
|
+
|
|
105
|
+
On a Mac, develop inside a Linux VM with nested virtualization (Apple M3 or newer, macOS 15 or newer). It works, but it is slow, and its timings mean nothing. To run `make` targets from the Mac, set `DEV_VM` in a `Makefile.local` file (git ignores it) to the command that runs its arguments inside that VM; targets that need Linux then re-run there automatically. See the top of the `Makefile`.
|
|
106
|
+
|
|
107
|
+
## Install
|
|
108
|
+
|
|
109
|
+
emberpool is a pre-release, so pip needs `--pre`:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pip install --pre emberpool
|
|
113
|
+
# or, in a uv project:
|
|
114
|
+
uv add --prerelease=allow emberpool
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Then prepare the host once, as root. `setup` downloads Firecracker, the guest kernel and Alpine Linux, checks each against a pinned SHA256, builds the guest image and writes a config file under `/var/lib/emberpool/`. `check` says, one line per problem, what is still missing:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
sudo .venv/bin/emberpool setup
|
|
121
|
+
sudo .venv/bin/emberpool check
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
After that, `SandboxPool()` needs no configuration. `sudo emberpool teardown` removes everything `setup` created; `pip uninstall` does not.
|
|
125
|
+
|
|
126
|
+
## Tested on
|
|
127
|
+
|
|
128
|
+
Only the configuration below has been tested. Anything not listed, including bare metal and x86_64, is untested.
|
|
129
|
+
|
|
130
|
+
| Host | Virtualization | Host kernel | Firecracker | Guest kernel | Python | Tests run |
|
|
131
|
+
|---|---|---|---|---|---|---|
|
|
132
|
+
| Ubuntu 24.04 LTS, aarch64 | Linux VM with nested KVM on Apple Silicon | 6.8 | v1.18.0 | 6.1 (Firecracker CI build, VMGenID) | 3.12 | Unit and VM tests, as root |
|
|
133
|
+
| Same host | Same | 6.8 | n/a | n/a | 3.12, 3.13, 3.14, 3.15 | Unit tests only |
|
|
134
|
+
| Fresh Ubuntu 24.04 LTS, aarch64, no Docker | Linux VM with nested KVM on Apple Silicon | 6.8 | v1.18.0 (from `emberpool setup`) | 6.1 (from `emberpool setup`) | 3.12 | Clean install from the wheel: `emberpool setup`, `sudo emberpool check`, a sandbox run with egress blocked |
|
|
135
|
+
|
|
136
|
+
## Using it as an agent tool
|
|
137
|
+
|
|
138
|
+
[`examples/agent_tool.py`](https://github.com/SamarjitDebnath/emberpool/blob/main/examples/agent_tool.py) gives a Claude agent a `run_python` tool backed by `SandboxPool.run()`: every call runs in a fresh, network-less microVM, and the host-recorded trace comes back with the output. It needs the `anthropic` package and an API key, and runs as root like everything else.
|
|
139
|
+
|
|
140
|
+
## Quick start from a checkout
|
|
141
|
+
|
|
142
|
+
From the repository root on the Linux host:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
make setup # install the venv, then run `emberpool setup` and `emberpool check`
|
|
146
|
+
make run CODE='print(1 + 1)'
|
|
147
|
+
make run CODE='import socket; socket.create_connection(("pypi.org", 443))' NETWORK=allow:pypi.org
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`make run` prints the guest's stdout, then the exit code, file changes and network trace on stderr.
|
|
151
|
+
|
|
152
|
+
**Docker hosts:** Docker's firewall drops forwarded traffic, and emberpool refuses to start rather than run with networking it cannot vouch for. `make firewall-allow` adds the two accept rules it needs for the default `ep` prefix. This changes the host firewall; read [setup](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/10-setup.md) first. The rules do not survive a reboot.
|
|
153
|
+
|
|
154
|
+
### Configuration
|
|
155
|
+
|
|
156
|
+
The library finds its files through `Settings`, or `EMBERPOOL_*` environment variables for any field left unset:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from pathlib import Path
|
|
160
|
+
from emberpool import SandboxPool, Settings
|
|
161
|
+
|
|
162
|
+
settings = Settings(rootfs=Path("/srv/emberpool/rootfs.ext4")) # the rest from EMBERPOOL_*
|
|
163
|
+
async with SandboxPool(size=2, settings=settings) as pool:
|
|
164
|
+
...
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Required: `EMBERPOOL_FIRECRACKER`, `EMBERPOOL_JAILER`, `EMBERPOOL_KERNEL`, `EMBERPOOL_ROOTFS`. Full table in the [API reference](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/20-api.md).
|
|
168
|
+
|
|
169
|
+
## Make targets
|
|
170
|
+
|
|
171
|
+
| Target | What it does |
|
|
172
|
+
|---|---|
|
|
173
|
+
| `make setup` | Install dependencies, fetch Firecracker, check the host |
|
|
174
|
+
| `make check` | Read-only check that the host has everything |
|
|
175
|
+
| `make rootfs` | Build the guest image with the agent |
|
|
176
|
+
| `make test` | Unit tests, no root; VM tests skip |
|
|
177
|
+
| `make vm-test` | Only the tests that boot real VMs, as root |
|
|
178
|
+
| `make test-all` | Every test, as root, then a leftover check |
|
|
179
|
+
| `make run CODE=... NETWORK=... TIMEOUT=...` | Run code in a fresh sandbox |
|
|
180
|
+
| `make leftovers` | List sockets, namespaces, links, tables or processes a run left behind |
|
|
181
|
+
| `make firewall-show` / `firewall-allow` | Inspect or open Docker's `DOCKER-USER` chain for sandbox uplinks |
|
|
182
|
+
| `make clean` / `distclean` | Remove caches; also the venv |
|
|
183
|
+
|
|
184
|
+
Override paths on the command line, for example `make vm-test FC_DIR=/opt/fc`. `make` alone lists everything.
|
|
185
|
+
|
|
186
|
+
## Project layout
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
src/emberpool/
|
|
190
|
+
__init__.py public API: SandboxPool, Sandbox, Result, Settings
|
|
191
|
+
pool.py warm pool, checkout, replacement, timeouts
|
|
192
|
+
engine.py Engine / NetPolicy / ExecClient protocols
|
|
193
|
+
_firecracker.py Firecracker engine (the only module that knows Firecracker)
|
|
194
|
+
_jailer.py jail setup
|
|
195
|
+
netpolicy.py per-VM namespaces, taps, host nftables table
|
|
196
|
+
_resolver.py allowlisting DNS resolver
|
|
197
|
+
trace.py host trace from nftables logs and DNS events
|
|
198
|
+
exec_client.py host side of the vsock protocol
|
|
199
|
+
guest/agent.py runs inside the VM (standard library only)
|
|
200
|
+
scripts/
|
|
201
|
+
build-rootfs.sh guest image builder
|
|
202
|
+
run.py one-shot runner used by `make run`
|
|
203
|
+
docs/ scope, setup, API, decisions, engineering rules
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Documentation
|
|
207
|
+
|
|
208
|
+
- [Comparison](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/comparison.md): emberpool next to microsandbox, CubeSandbox and E2B, from their own docs
|
|
209
|
+
- [Threat model](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/decisions/0001-threat-model.md): what emberpool defends against, what it does not, and why
|
|
210
|
+
- [Scope](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/00-scope.md): what emberpool does and does not do, trust model, limitations
|
|
211
|
+
- [Setup](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/10-setup.md): host, kernel, guest image, networking, firewall, and a [production checklist](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/10-setup.md#production-checklist)
|
|
212
|
+
- [API](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/20-api.md): `SandboxPool`, `Sandbox`, `Result`, `Settings`, trace format
|
|
213
|
+
- [Decisions](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/30-decisions.md): design choices and what was rejected
|
|
214
|
+
- [Engineering rules](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/40-rules.md): the safety rules every change follows
|
|
215
|
+
|
|
216
|
+
## Known limitations
|
|
217
|
+
|
|
218
|
+
- Single host, one fixed-size pool per host: a second pool on the same host refuses to start. No clustering or persistence between runs.
|
|
219
|
+
- asyncio only; no blocking API in v0.1.
|
|
220
|
+
- No file transfer into or out of the sandbox yet (planned for v0.2).
|
|
221
|
+
- The file-change list shows end state only and misses files created and then deleted. It relies on the guest flushing its disk before replying, so code in the sandbox can hide changes from it.
|
|
222
|
+
- Verified on aarch64 only.
|
|
223
|
+
|
|
224
|
+
## Contributing
|
|
225
|
+
|
|
226
|
+
Read [docs/40-rules.md](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/40-rules.md) before changing code. The guest is treated as hostile, isolation fails closed, host commands never go through a shell, and every resource has a teardown. A change that breaks a rule is wrong even if its tests pass. Run `make test-all` and `make leftovers` before sending a change.
|
|
227
|
+
|
|
228
|
+
## Security
|
|
229
|
+
|
|
230
|
+
Report vulnerabilities privately; see the [security policy](https://github.com/SamarjitDebnath/emberpool/blob/main/SECURITY.md).
|
|
231
|
+
|
|
232
|
+
## License
|
|
233
|
+
|
|
234
|
+
[MIT](https://github.com/SamarjitDebnath/emberpool/blob/main/LICENSE)
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# emberpool
|
|
2
|
+
|
|
3
|
+
Firecracker microVM sandboxes for AI agent code, with deny-by-default egress and a host-side audit trail that the sandboxed code cannot alter.
|
|
4
|
+
|
|
5
|
+
emberpool is a Python library that gives an AI agent a disposable Linux microVM for each piece of code it runs, and a host-recorded log of what that code tried to do over the network.
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from emberpool import SandboxPool
|
|
9
|
+
|
|
10
|
+
async with SandboxPool(size=4, network="allow:pypi.org,files.pythonhosted.org") as pool:
|
|
11
|
+
result = await pool.run(
|
|
12
|
+
"import socket; socket.create_connection(('pypi.org', 443)); print('reached pypi')",
|
|
13
|
+
timeout=60, # one deadline: waiting for a free VM plus the run itself
|
|
14
|
+
)
|
|
15
|
+
print(result.exit_code, result.stdout)
|
|
16
|
+
for event in result.trace: # DNS queries and connection verdicts, seen by the host
|
|
17
|
+
print(event)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
> **Status: pre-alpha (0.1.0a1).** v0.1 is implemented and runs end to end on an aarch64 development host under nested virtualization. It has not been run on bare metal, and the API may change in any 0.x minor release (see the [changelog](https://github.com/SamarjitDebnath/emberpool/blob/main/CHANGELOG.md)). Performance targets are unmeasured; timings from the nested-virtualization development VM are not benchmarks.
|
|
21
|
+
|
|
22
|
+
## Why
|
|
23
|
+
|
|
24
|
+
Agents run code they wrote a moment ago, and sometimes code someone tricked them into writing. emberpool is built around three ideas:
|
|
25
|
+
|
|
26
|
+
- **A real VM boundary.** Each run gets its own Firecracker microVM under KVM with its own guest kernel, launched through Firecracker's jailer. Untrusted code never shares the host kernel.
|
|
27
|
+
- **Speed from snapshots.** A template VM is booted once, with the in-guest agent running, and snapshotted. Sandboxes are restored from it and kept warm, so a run does not pay for a kernel boot. Each run starts a fresh `python3` process inside its VM, and every VM is destroyed after one run.
|
|
28
|
+
- **Evidence, not self-reporting.** Network policy and the trace live on the host. The sandbox cannot hide a DNS lookup or a connection attempt, because the guest is never asked.
|
|
29
|
+
|
|
30
|
+
## How it works
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
your agent ── await pool.run(code) ──▶ emberpool (host, Python, root)
|
|
34
|
+
│ restore from snapshot
|
|
35
|
+
▼
|
|
36
|
+
Firecracker microVM, jailed
|
|
37
|
+
own kernel · 1 vCPU · 512 MiB
|
|
38
|
+
agent on vsock · own netns
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
1. **Build once.** Boot a template VM, wait for the in-guest agent, snapshot memory and state.
|
|
42
|
+
2. **Restore many.** Each sandbox gets a fresh jail, a fresh scratch drive over a shared read-only root filesystem, and its own network namespace, then loads the snapshot.
|
|
43
|
+
3. **Run.** Code goes to the guest over vsock. A replacement VM is restored in the background.
|
|
44
|
+
4. **Tear down.** The VM is killed, its namespace deleted, and the host's trace returned with the result.
|
|
45
|
+
|
|
46
|
+
Networking is deny-by-default. When you allowlist domain names, emberpool's own DNS resolver answers only those names, and nftables on the host admits connections only to the addresses it returned. Every query and every verdict is logged.
|
|
47
|
+
|
|
48
|
+
## What you can trust in a `Result`
|
|
49
|
+
|
|
50
|
+
| Field | Source | Trust |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| `trace` | Host resolver and nftables | Complete; the guest cannot alter it |
|
|
53
|
+
| `timed_out` | Host | The host killed the VM |
|
|
54
|
+
| `error` | Host | `None` if the guest returned a result; `"timeout"` or `"agent"` otherwise |
|
|
55
|
+
| `file_changes` | Host reads the scratch drive (never mounts it) | Advisory; end state only |
|
|
56
|
+
| `stdout`, `stderr`, `exit_code` | Guest agent | Convenience; code in the sandbox can forge them |
|
|
57
|
+
|
|
58
|
+
## Requirements
|
|
59
|
+
|
|
60
|
+
Check these before installing:
|
|
61
|
+
|
|
62
|
+
- **Root.** v0.1 must run as root: the jailer and per-sandbox networking need it. Each Firecracker process still drops privileges inside its jail.
|
|
63
|
+
- **Linux with KVM** (`/dev/kvm`).
|
|
64
|
+
- **aarch64.** It is the only architecture verified so far; others may work but are untested.
|
|
65
|
+
|
|
66
|
+
The host also needs:
|
|
67
|
+
|
|
68
|
+
- Firecracker v1.18.0 and its jailer.
|
|
69
|
+
- A 6.1 guest kernel with device-tree VMGenID support, so restored clones get fresh randomness. See [setup](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/10-setup.md) for how to check.
|
|
70
|
+
- Python 3.12 or newer; [uv](https://docs.astral.sh/uv/) for working from a checkout.
|
|
71
|
+
- `iproute2`, `nftables`, `e2fsprogs` and `tar`. No Docker: `emberpool setup` builds the guest image itself.
|
|
72
|
+
|
|
73
|
+
On a Mac, develop inside a Linux VM with nested virtualization (Apple M3 or newer, macOS 15 or newer). It works, but it is slow, and its timings mean nothing. To run `make` targets from the Mac, set `DEV_VM` in a `Makefile.local` file (git ignores it) to the command that runs its arguments inside that VM; targets that need Linux then re-run there automatically. See the top of the `Makefile`.
|
|
74
|
+
|
|
75
|
+
## Install
|
|
76
|
+
|
|
77
|
+
emberpool is a pre-release, so pip needs `--pre`:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install --pre emberpool
|
|
81
|
+
# or, in a uv project:
|
|
82
|
+
uv add --prerelease=allow emberpool
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Then prepare the host once, as root. `setup` downloads Firecracker, the guest kernel and Alpine Linux, checks each against a pinned SHA256, builds the guest image and writes a config file under `/var/lib/emberpool/`. `check` says, one line per problem, what is still missing:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
sudo .venv/bin/emberpool setup
|
|
89
|
+
sudo .venv/bin/emberpool check
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
After that, `SandboxPool()` needs no configuration. `sudo emberpool teardown` removes everything `setup` created; `pip uninstall` does not.
|
|
93
|
+
|
|
94
|
+
## Tested on
|
|
95
|
+
|
|
96
|
+
Only the configuration below has been tested. Anything not listed, including bare metal and x86_64, is untested.
|
|
97
|
+
|
|
98
|
+
| Host | Virtualization | Host kernel | Firecracker | Guest kernel | Python | Tests run |
|
|
99
|
+
|---|---|---|---|---|---|---|
|
|
100
|
+
| Ubuntu 24.04 LTS, aarch64 | Linux VM with nested KVM on Apple Silicon | 6.8 | v1.18.0 | 6.1 (Firecracker CI build, VMGenID) | 3.12 | Unit and VM tests, as root |
|
|
101
|
+
| Same host | Same | 6.8 | n/a | n/a | 3.12, 3.13, 3.14, 3.15 | Unit tests only |
|
|
102
|
+
| Fresh Ubuntu 24.04 LTS, aarch64, no Docker | Linux VM with nested KVM on Apple Silicon | 6.8 | v1.18.0 (from `emberpool setup`) | 6.1 (from `emberpool setup`) | 3.12 | Clean install from the wheel: `emberpool setup`, `sudo emberpool check`, a sandbox run with egress blocked |
|
|
103
|
+
|
|
104
|
+
## Using it as an agent tool
|
|
105
|
+
|
|
106
|
+
[`examples/agent_tool.py`](https://github.com/SamarjitDebnath/emberpool/blob/main/examples/agent_tool.py) gives a Claude agent a `run_python` tool backed by `SandboxPool.run()`: every call runs in a fresh, network-less microVM, and the host-recorded trace comes back with the output. It needs the `anthropic` package and an API key, and runs as root like everything else.
|
|
107
|
+
|
|
108
|
+
## Quick start from a checkout
|
|
109
|
+
|
|
110
|
+
From the repository root on the Linux host:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
make setup # install the venv, then run `emberpool setup` and `emberpool check`
|
|
114
|
+
make run CODE='print(1 + 1)'
|
|
115
|
+
make run CODE='import socket; socket.create_connection(("pypi.org", 443))' NETWORK=allow:pypi.org
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`make run` prints the guest's stdout, then the exit code, file changes and network trace on stderr.
|
|
119
|
+
|
|
120
|
+
**Docker hosts:** Docker's firewall drops forwarded traffic, and emberpool refuses to start rather than run with networking it cannot vouch for. `make firewall-allow` adds the two accept rules it needs for the default `ep` prefix. This changes the host firewall; read [setup](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/10-setup.md) first. The rules do not survive a reboot.
|
|
121
|
+
|
|
122
|
+
### Configuration
|
|
123
|
+
|
|
124
|
+
The library finds its files through `Settings`, or `EMBERPOOL_*` environment variables for any field left unset:
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from pathlib import Path
|
|
128
|
+
from emberpool import SandboxPool, Settings
|
|
129
|
+
|
|
130
|
+
settings = Settings(rootfs=Path("/srv/emberpool/rootfs.ext4")) # the rest from EMBERPOOL_*
|
|
131
|
+
async with SandboxPool(size=2, settings=settings) as pool:
|
|
132
|
+
...
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Required: `EMBERPOOL_FIRECRACKER`, `EMBERPOOL_JAILER`, `EMBERPOOL_KERNEL`, `EMBERPOOL_ROOTFS`. Full table in the [API reference](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/20-api.md).
|
|
136
|
+
|
|
137
|
+
## Make targets
|
|
138
|
+
|
|
139
|
+
| Target | What it does |
|
|
140
|
+
|---|---|
|
|
141
|
+
| `make setup` | Install dependencies, fetch Firecracker, check the host |
|
|
142
|
+
| `make check` | Read-only check that the host has everything |
|
|
143
|
+
| `make rootfs` | Build the guest image with the agent |
|
|
144
|
+
| `make test` | Unit tests, no root; VM tests skip |
|
|
145
|
+
| `make vm-test` | Only the tests that boot real VMs, as root |
|
|
146
|
+
| `make test-all` | Every test, as root, then a leftover check |
|
|
147
|
+
| `make run CODE=... NETWORK=... TIMEOUT=...` | Run code in a fresh sandbox |
|
|
148
|
+
| `make leftovers` | List sockets, namespaces, links, tables or processes a run left behind |
|
|
149
|
+
| `make firewall-show` / `firewall-allow` | Inspect or open Docker's `DOCKER-USER` chain for sandbox uplinks |
|
|
150
|
+
| `make clean` / `distclean` | Remove caches; also the venv |
|
|
151
|
+
|
|
152
|
+
Override paths on the command line, for example `make vm-test FC_DIR=/opt/fc`. `make` alone lists everything.
|
|
153
|
+
|
|
154
|
+
## Project layout
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
src/emberpool/
|
|
158
|
+
__init__.py public API: SandboxPool, Sandbox, Result, Settings
|
|
159
|
+
pool.py warm pool, checkout, replacement, timeouts
|
|
160
|
+
engine.py Engine / NetPolicy / ExecClient protocols
|
|
161
|
+
_firecracker.py Firecracker engine (the only module that knows Firecracker)
|
|
162
|
+
_jailer.py jail setup
|
|
163
|
+
netpolicy.py per-VM namespaces, taps, host nftables table
|
|
164
|
+
_resolver.py allowlisting DNS resolver
|
|
165
|
+
trace.py host trace from nftables logs and DNS events
|
|
166
|
+
exec_client.py host side of the vsock protocol
|
|
167
|
+
guest/agent.py runs inside the VM (standard library only)
|
|
168
|
+
scripts/
|
|
169
|
+
build-rootfs.sh guest image builder
|
|
170
|
+
run.py one-shot runner used by `make run`
|
|
171
|
+
docs/ scope, setup, API, decisions, engineering rules
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Documentation
|
|
175
|
+
|
|
176
|
+
- [Comparison](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/comparison.md): emberpool next to microsandbox, CubeSandbox and E2B, from their own docs
|
|
177
|
+
- [Threat model](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/decisions/0001-threat-model.md): what emberpool defends against, what it does not, and why
|
|
178
|
+
- [Scope](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/00-scope.md): what emberpool does and does not do, trust model, limitations
|
|
179
|
+
- [Setup](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/10-setup.md): host, kernel, guest image, networking, firewall, and a [production checklist](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/10-setup.md#production-checklist)
|
|
180
|
+
- [API](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/20-api.md): `SandboxPool`, `Sandbox`, `Result`, `Settings`, trace format
|
|
181
|
+
- [Decisions](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/30-decisions.md): design choices and what was rejected
|
|
182
|
+
- [Engineering rules](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/40-rules.md): the safety rules every change follows
|
|
183
|
+
|
|
184
|
+
## Known limitations
|
|
185
|
+
|
|
186
|
+
- Single host, one fixed-size pool per host: a second pool on the same host refuses to start. No clustering or persistence between runs.
|
|
187
|
+
- asyncio only; no blocking API in v0.1.
|
|
188
|
+
- No file transfer into or out of the sandbox yet (planned for v0.2).
|
|
189
|
+
- The file-change list shows end state only and misses files created and then deleted. It relies on the guest flushing its disk before replying, so code in the sandbox can hide changes from it.
|
|
190
|
+
- Verified on aarch64 only.
|
|
191
|
+
|
|
192
|
+
## Contributing
|
|
193
|
+
|
|
194
|
+
Read [docs/40-rules.md](https://github.com/SamarjitDebnath/emberpool/blob/main/docs/40-rules.md) before changing code. The guest is treated as hostile, isolation fails closed, host commands never go through a shell, and every resource has a teardown. A change that breaks a rule is wrong even if its tests pass. Run `make test-all` and `make leftovers` before sending a change.
|
|
195
|
+
|
|
196
|
+
## Security
|
|
197
|
+
|
|
198
|
+
Report vulnerabilities privately; see the [security policy](https://github.com/SamarjitDebnath/emberpool/blob/main/SECURITY.md).
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
[MIT](https://github.com/SamarjitDebnath/emberpool/blob/main/LICENSE)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "emberpool"
|
|
3
|
+
version = "0.1.0a1"
|
|
4
|
+
description = "Firecracker microVM sandboxes for AI agent code, with deny-by-default egress and a host-side audit trail that the sandboxed code cannot alter."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
keywords = [
|
|
10
|
+
"sandbox",
|
|
11
|
+
"firecracker",
|
|
12
|
+
"microvm",
|
|
13
|
+
"ai-agents",
|
|
14
|
+
"llm",
|
|
15
|
+
"security",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
19
|
+
"Framework :: AsyncIO",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
22
|
+
"Operating System :: POSIX :: Linux",
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Programming Language :: Python :: 3.14",
|
|
28
|
+
"Programming Language :: Python :: 3.15",
|
|
29
|
+
"Topic :: Security",
|
|
30
|
+
"Typing :: Typed",
|
|
31
|
+
]
|
|
32
|
+
dependencies = [
|
|
33
|
+
"dnspython>=2.9.2",
|
|
34
|
+
"httpx>=0.29.0",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[[project.authors]]
|
|
38
|
+
name = "Samarjit Debnath"
|
|
39
|
+
|
|
40
|
+
[project.scripts]
|
|
41
|
+
emberpool = "emberpool.cli:main"
|
|
42
|
+
|
|
43
|
+
[project.urls]
|
|
44
|
+
Homepage = "https://github.com/SamarjitDebnath/emberpool"
|
|
45
|
+
Documentation = "https://github.com/SamarjitDebnath/emberpool/tree/main/docs"
|
|
46
|
+
Source = "https://github.com/SamarjitDebnath/emberpool"
|
|
47
|
+
Issues = "https://github.com/SamarjitDebnath/emberpool/issues"
|
|
48
|
+
Changelog = "https://github.com/SamarjitDebnath/emberpool/blob/main/CHANGELOG.md"
|
|
49
|
+
Security = "https://github.com/SamarjitDebnath/emberpool/security/policy"
|
|
50
|
+
|
|
51
|
+
[build-system]
|
|
52
|
+
requires = ["uv_build>=0.13.10,<0.14.0"]
|
|
53
|
+
build-backend = "uv_build"
|
|
54
|
+
|
|
55
|
+
[dependency-groups]
|
|
56
|
+
dev = [
|
|
57
|
+
"pytest>=9.2.0",
|
|
58
|
+
"pytest-asyncio>=1.5.0",
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
[tool.pytest.ini_options]
|
|
62
|
+
testpaths = ["tests"]
|
|
63
|
+
norecursedirs = [
|
|
64
|
+
".worktrees",
|
|
65
|
+
".git",
|
|
66
|
+
".venv",
|
|
67
|
+
"build",
|
|
68
|
+
"dist",
|
|
69
|
+
]
|
|
70
|
+
asyncio_mode = "auto"
|
|
71
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
72
|
+
markers = ["vm: needs root, KVM or the dev VM; skipped when unavailable"]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "emberpool"
|
|
3
|
+
version = "0.1.0a1"
|
|
4
|
+
description = "Firecracker microVM sandboxes for AI agent code, with deny-by-default egress and a host-side audit trail that the sandboxed code cannot alter."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
# 3.12 is the lowest version the code and tests support: trace.py uses
|
|
7
|
+
# os.setns, and the resolver tests need 3.12's asyncio datagram transport.
|
|
8
|
+
requires-python = ">=3.12"
|
|
9
|
+
license = "MIT"
|
|
10
|
+
license-files = ["LICENSE"]
|
|
11
|
+
authors = [{ name = "Samarjit Debnath" }]
|
|
12
|
+
keywords = ["sandbox", "firecracker", "microvm", "ai-agents", "llm", "security"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
15
|
+
"Framework :: AsyncIO",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: POSIX :: Linux",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
24
|
+
"Programming Language :: Python :: 3.15",
|
|
25
|
+
"Topic :: Security",
|
|
26
|
+
"Typing :: Typed",
|
|
27
|
+
]
|
|
28
|
+
dependencies = [
|
|
29
|
+
"dnspython>=2.9.2",
|
|
30
|
+
# emberpool setup downloads Firecracker, the guest kernel and Alpine.
|
|
31
|
+
"httpx>=0.29.0",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
emberpool = "emberpool.cli:main"
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://github.com/SamarjitDebnath/emberpool"
|
|
39
|
+
Documentation = "https://github.com/SamarjitDebnath/emberpool/tree/main/docs"
|
|
40
|
+
Source = "https://github.com/SamarjitDebnath/emberpool"
|
|
41
|
+
Issues = "https://github.com/SamarjitDebnath/emberpool/issues"
|
|
42
|
+
Changelog = "https://github.com/SamarjitDebnath/emberpool/blob/main/CHANGELOG.md"
|
|
43
|
+
Security = "https://github.com/SamarjitDebnath/emberpool/security/policy"
|
|
44
|
+
|
|
45
|
+
[build-system]
|
|
46
|
+
requires = ["uv_build>=0.13.10,<0.14.0"]
|
|
47
|
+
build-backend = "uv_build"
|
|
48
|
+
|
|
49
|
+
[dependency-groups]
|
|
50
|
+
dev = [
|
|
51
|
+
"pytest>=9.2.0",
|
|
52
|
+
"pytest-asyncio>=1.5.0",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[tool.pytest.ini_options]
|
|
56
|
+
testpaths = ["tests"]
|
|
57
|
+
norecursedirs = [".worktrees", ".git", ".venv", "build", "dist"]
|
|
58
|
+
asyncio_mode = "auto"
|
|
59
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
60
|
+
markers = [
|
|
61
|
+
"vm: needs root, KVM or the dev VM; skipped when unavailable",
|
|
62
|
+
]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""emberpool: warm-pool Firecracker microVM sandboxes for AI agents.
|
|
2
|
+
|
|
3
|
+
The public API is exactly what this module exports.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from emberpool._types import IsolationError, Result
|
|
7
|
+
from emberpool._settings import Settings
|
|
8
|
+
from emberpool.pool import Sandbox, SandboxPool
|
|
9
|
+
|
|
10
|
+
__all__ = ["SandboxPool", "Sandbox", "Result", "Settings", "IsolationError"]
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""Files `emberpool setup` puts into the guest root filesystem.
|
|
2
|
+
|
|
3
|
+
ep-init guest PID 1: overlay on the scratch drive, then busybox init
|
|
4
|
+
inittab busybox init table: early setup, then the agent, respawned
|
|
5
|
+
|
|
6
|
+
The agent itself is emberpool/guest/agent.py with its vendored _protocol.py.
|
|
7
|
+
"""
|