agentbox-sandbox 0.4.0__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.
@@ -0,0 +1,5 @@
1
+ AGENTBOX_HOST=0.0.0.0
2
+ AGENTBOX_PORT=8080
3
+ AGENTBOX_LOG_LEVEL=INFO
4
+ AGENTBOX_DEFAULT_TIMEOUT_SECONDS=30
5
+ AGENTBOX_SANDBOX_BACKEND=subprocess
@@ -0,0 +1,11 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - uses: actions/checkout@v4
8
+ - uses: actions/setup-python@v5
9
+ with: {python-version: "3.12"}
10
+ - run: pip install -e ".[dev]"
11
+ - run: pytest tests/ -v
@@ -0,0 +1,4 @@
1
+ __pycache__/
2
+ .venv/
3
+ .pytest_cache/
4
+ dist/
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ ## [0.4.0] - 2026-09-14
4
+
5
+ ### Added
6
+ - `limits.memory_mb` on `POST /v1/run` — applies `RLIMIT_AS` in the child process (16–8192 MB)
7
+ - Optional `AGENTBOX_DEFAULT_MEMORY_MB` and SDK `memory_mb=` passthrough
8
+
9
+ ## [0.3.0] - 2026-08-19
10
+
11
+ ### Added
12
+ - Workspace snapshot/restore (`snapshot: true` / `snapshot_id`) so agents can keep files across runs
13
+
14
+ ## [0.2.0] - 2026-08-19
15
+
16
+ ### Added
17
+ - JavaScript/Node runtime (`language: javascript|node`)
18
+ - Per-request `limits.timeout_seconds` (408 on timeout)
19
+ - TypeScript client at `sdk/ts/client.ts`
20
+ - Credential stripping when backend is not `unrestricted`
21
+
22
+ ### Notes
23
+ - Isolation is still subprocess, not gVisor
24
+
25
+ ## [0.1.0] - 2026-08-18
26
+
27
+ ### Added
28
+ - FastAPI service with /health and /v1/run
29
+ - Subprocess sandbox backend (MVP)
30
+ - Python SDK client skeleton
@@ -0,0 +1,30 @@
1
+ # Contributing
2
+
3
+ ## Running tests
4
+
5
+ Prefer Docker Compose:
6
+
7
+ ```bash
8
+ docker compose run --rm test
9
+ docker compose up agentbox # API on :8080 for manual checks
10
+ ```
11
+
12
+ Locally:
13
+
14
+ ```bash
15
+ pip install -e ".[dev]"
16
+ pytest tests/ -v
17
+ agentbox serve
18
+ curl http://localhost:8080/health
19
+ ```
20
+
21
+ ## Pull requests
22
+
23
+ - Treat sandbox changes as security-sensitive; document limitations honestly
24
+ - Update README/CHANGELOG for API or limit changes
25
+ - Prefer small PRs with a clear test plan
26
+
27
+ ## Commit style
28
+
29
+ - Imperative subject line; mention the user-facing why when relevant
30
+ - Do not add AI co-author trailers (e.g. Co-authored-by: Cursor) to commits.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 agentbox contributors
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,171 @@
1
+ Metadata-Version: 2.5
2
+ Name: agentbox-sandbox
3
+ Version: 0.4.0
4
+ Summary: Self-hosted code execution sandbox for AI agents
5
+ Project-URL: Homepage, https://github.com/yashshah9/agentbox
6
+ Project-URL: Repository, https://github.com/yashshah9/agentbox
7
+ Project-URL: Issues, https://github.com/yashshah9/agentbox/issues
8
+ Author-email: Yash Shah <yash376351@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Requires-Python: >=3.11
12
+ Requires-Dist: fastapi>=0.111
13
+ Requires-Dist: pydantic-settings>=2.2
14
+ Requires-Dist: pydantic>=2.6
15
+ Requires-Dist: structlog>=24.1
16
+ Requires-Dist: uvicorn[standard]>=0.29
17
+ Provides-Extra: dev
18
+ Requires-Dist: httpx>=0.27; extra == 'dev'
19
+ Requires-Dist: mypy>=1.9; extra == 'dev'
20
+ Requires-Dist: pytest>=8.0; extra == 'dev'
21
+ Requires-Dist: ruff>=0.4; extra == 'dev'
22
+ Description-Content-Type: text/markdown
23
+
24
+ # agentbox
25
+
26
+ Self-hosted **code execution sandbox** for AI agents — one `docker compose up` gives you an HTTP API for running untrusted code in isolated environments.
27
+
28
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
29
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
30
+ [![CI](https://github.com/yashshah9/agentbox/actions/workflows/ci.yml/badge.svg)](https://github.com/yashshah9/agentbox/actions/workflows/ci.yml)
31
+
32
+ > **Status:** v0.4 — Python + Node subprocess sandbox, timeouts, `limits.memory_mb` via `RLIMIT_AS`, TypeScript client, workspace snapshots.
33
+
34
+ ## 60-second try
35
+
36
+ ```bash
37
+ docker compose up agentbox # API on :8080
38
+ # in another shell:
39
+ curl -s http://localhost:8080/health
40
+ curl -s -X POST http://localhost:8080/v1/run \
41
+ -H 'Content-Type: application/json' \
42
+ -d '{"code":"print(sum(range(10)))"}'
43
+ docker compose run --rm test # pytest
44
+ ```
45
+
46
+ ## Why this vs alternatives
47
+
48
+ | Approach | Strength | Gap |
49
+ |----------|----------|-----|
50
+ | **agentbox** | Self-hosted HTTP API + SDK, one compose file | Subprocess isolation today, not gVisor |
51
+ | Hosted sandboxes (E2B, etc.) | Strong isolation, managed | Per-second cost; data leaves your network |
52
+ | Raw `docker exec` | Familiar | No agent-oriented API / snapshots / limits |
53
+ | YOLO in the agent process | Zero infra | Full host compromise risk |
54
+
55
+ ## Problem
56
+
57
+ Every agent that writes and runs code needs a safe execution environment. Teams either YOLO in shared containers or pay per-second for hosted sandboxes. Self-hosting gVisor/Firecracker is weeks of work.
58
+
59
+ ## Key features (v0.4)
60
+
61
+ - HTTP API: `POST /v1/run` executes Python or JavaScript
62
+ - Per-request `limits.timeout_seconds` (HTTP 408 on timeout)
63
+ - Per-request `limits.memory_mb` (sets `RLIMIT_AS` in the child process; 16–8192)
64
+ - Workspace snapshots: `"snapshot": true` then `"snapshot_id"`
65
+ - Python SDK + TypeScript client (`sdk/ts/client.ts`)
66
+ - Docker image includes Node.js for the JS runtime
67
+ - Credential stripping when the backend is not `unrestricted`
68
+
69
+ ## Architecture
70
+
71
+ ```
72
+ Agent / SDK
73
+ └── POST /v1/run
74
+ └── SubprocessSandbox (MVP)
75
+ └── (next) gVisor / Docker backend
76
+ ```
77
+
78
+ | Component | Technology | Why |
79
+ |-----------|------------|-----|
80
+ | API | FastAPI | Async-ready, OpenAPI docs, widely adopted |
81
+ | Server | uvicorn | Standard ASGI server |
82
+ | Config | pydantic-settings | Typed env config |
83
+ | Tests | pytest + httpx TestClient | Fast API testing |
84
+
85
+ ## Installation
86
+
87
+ ```bash
88
+ pip install agentbox-sandbox
89
+ pip install -e ".[dev]"
90
+ ```
91
+
92
+ ## Usage
93
+
94
+ ### Start server
95
+
96
+ ```bash
97
+ agentbox serve
98
+ # or
99
+ docker compose up agentbox
100
+ ```
101
+
102
+ ### Run code
103
+
104
+ ```bash
105
+ curl -X POST http://localhost:8080/v1/run \
106
+ -H 'Content-Type: application/json' \
107
+ -d '{"code": "print(sum(range(10)))"}'
108
+
109
+ curl -X POST http://localhost:8080/v1/run \
110
+ -H 'Content-Type: application/json' \
111
+ -d '{"code": "x = bytearray(10**9)", "limits": {"memory_mb": 64, "timeout_seconds": 5}}'
112
+ ```
113
+
114
+ ### Python SDK
115
+
116
+ ```python
117
+ from agentbox.sdk.client import AgentboxClient
118
+
119
+ client = AgentboxClient("http://localhost:8080")
120
+ print(client.health())
121
+ print(client.run("print('hello')"))
122
+ print(client.run("console.log('hello')", language="javascript", timeout_seconds=5))
123
+ print(client.run("x = bytearray(10**8)", memory_mb=64))
124
+ snap = client.run("open('memo.txt','w').write('kept')", snapshot=True)
125
+ print(client.run("print(open('memo.txt').read())", snapshot_id=snap["snapshot_id"]))
126
+ client.close()
127
+ ```
128
+
129
+ ## Docker
130
+
131
+ ```bash
132
+ docker compose up agentbox # start API on :8080
133
+ docker compose run --rm test # run unit tests
134
+ ```
135
+
136
+ ## Configuration
137
+
138
+ | Variable | Default | Description |
139
+ |----------|---------|-------------|
140
+ | `AGENTBOX_HOST` | `0.0.0.0` | Bind host |
141
+ | `AGENTBOX_PORT` | `8080` | Bind port |
142
+ | `AGENTBOX_DEFAULT_TIMEOUT_SECONDS` | `30` | Execution timeout |
143
+ | `AGENTBOX_DEFAULT_MEMORY_MB` | unset | Optional default `RLIMIT_AS` cap |
144
+ | `AGENTBOX_SANDBOX_BACKEND` | `subprocess` | Backend selector |
145
+ | `AGENTBOX_SNAPSHOT_DIR` | `/tmp/agentbox-snapshots` | Workspace snapshot store |
146
+
147
+ ## Running tests
148
+
149
+ ```bash
150
+ pytest tests/ -v
151
+ ```
152
+
153
+ ## Roadmap
154
+
155
+ - [x] Node.js runtime + TypeScript client + per-run timeout
156
+ - [x] Filesystem snapshot/restore (tar workspaces)
157
+ - [x] `limits.memory_mb` via `RLIMIT_AS`
158
+ - [ ] gVisor runsc backend with warm pool
159
+ - [ ] Default-deny egress with allowlists (kernel netns)
160
+
161
+ ## License
162
+
163
+ MIT
164
+
165
+ ## Known limitations (v0.4)
166
+
167
+ - Subprocess sandbox only — **not production-grade isolation**
168
+ - `RLIMIT_AS` is a soft address-space cap, not a cgroup memory controller
169
+ - Credential stripping is not a network namespace
170
+ - Single-node, no warm pool
171
+ - TypeScript client is source-only (not published to npm)
@@ -0,0 +1,148 @@
1
+ # agentbox
2
+
3
+ Self-hosted **code execution sandbox** for AI agents — one `docker compose up` gives you an HTTP API for running untrusted code in isolated environments.
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
7
+ [![CI](https://github.com/yashshah9/agentbox/actions/workflows/ci.yml/badge.svg)](https://github.com/yashshah9/agentbox/actions/workflows/ci.yml)
8
+
9
+ > **Status:** v0.4 — Python + Node subprocess sandbox, timeouts, `limits.memory_mb` via `RLIMIT_AS`, TypeScript client, workspace snapshots.
10
+
11
+ ## 60-second try
12
+
13
+ ```bash
14
+ docker compose up agentbox # API on :8080
15
+ # in another shell:
16
+ curl -s http://localhost:8080/health
17
+ curl -s -X POST http://localhost:8080/v1/run \
18
+ -H 'Content-Type: application/json' \
19
+ -d '{"code":"print(sum(range(10)))"}'
20
+ docker compose run --rm test # pytest
21
+ ```
22
+
23
+ ## Why this vs alternatives
24
+
25
+ | Approach | Strength | Gap |
26
+ |----------|----------|-----|
27
+ | **agentbox** | Self-hosted HTTP API + SDK, one compose file | Subprocess isolation today, not gVisor |
28
+ | Hosted sandboxes (E2B, etc.) | Strong isolation, managed | Per-second cost; data leaves your network |
29
+ | Raw `docker exec` | Familiar | No agent-oriented API / snapshots / limits |
30
+ | YOLO in the agent process | Zero infra | Full host compromise risk |
31
+
32
+ ## Problem
33
+
34
+ Every agent that writes and runs code needs a safe execution environment. Teams either YOLO in shared containers or pay per-second for hosted sandboxes. Self-hosting gVisor/Firecracker is weeks of work.
35
+
36
+ ## Key features (v0.4)
37
+
38
+ - HTTP API: `POST /v1/run` executes Python or JavaScript
39
+ - Per-request `limits.timeout_seconds` (HTTP 408 on timeout)
40
+ - Per-request `limits.memory_mb` (sets `RLIMIT_AS` in the child process; 16–8192)
41
+ - Workspace snapshots: `"snapshot": true` then `"snapshot_id"`
42
+ - Python SDK + TypeScript client (`sdk/ts/client.ts`)
43
+ - Docker image includes Node.js for the JS runtime
44
+ - Credential stripping when the backend is not `unrestricted`
45
+
46
+ ## Architecture
47
+
48
+ ```
49
+ Agent / SDK
50
+ └── POST /v1/run
51
+ └── SubprocessSandbox (MVP)
52
+ └── (next) gVisor / Docker backend
53
+ ```
54
+
55
+ | Component | Technology | Why |
56
+ |-----------|------------|-----|
57
+ | API | FastAPI | Async-ready, OpenAPI docs, widely adopted |
58
+ | Server | uvicorn | Standard ASGI server |
59
+ | Config | pydantic-settings | Typed env config |
60
+ | Tests | pytest + httpx TestClient | Fast API testing |
61
+
62
+ ## Installation
63
+
64
+ ```bash
65
+ pip install agentbox-sandbox
66
+ pip install -e ".[dev]"
67
+ ```
68
+
69
+ ## Usage
70
+
71
+ ### Start server
72
+
73
+ ```bash
74
+ agentbox serve
75
+ # or
76
+ docker compose up agentbox
77
+ ```
78
+
79
+ ### Run code
80
+
81
+ ```bash
82
+ curl -X POST http://localhost:8080/v1/run \
83
+ -H 'Content-Type: application/json' \
84
+ -d '{"code": "print(sum(range(10)))"}'
85
+
86
+ curl -X POST http://localhost:8080/v1/run \
87
+ -H 'Content-Type: application/json' \
88
+ -d '{"code": "x = bytearray(10**9)", "limits": {"memory_mb": 64, "timeout_seconds": 5}}'
89
+ ```
90
+
91
+ ### Python SDK
92
+
93
+ ```python
94
+ from agentbox.sdk.client import AgentboxClient
95
+
96
+ client = AgentboxClient("http://localhost:8080")
97
+ print(client.health())
98
+ print(client.run("print('hello')"))
99
+ print(client.run("console.log('hello')", language="javascript", timeout_seconds=5))
100
+ print(client.run("x = bytearray(10**8)", memory_mb=64))
101
+ snap = client.run("open('memo.txt','w').write('kept')", snapshot=True)
102
+ print(client.run("print(open('memo.txt').read())", snapshot_id=snap["snapshot_id"]))
103
+ client.close()
104
+ ```
105
+
106
+ ## Docker
107
+
108
+ ```bash
109
+ docker compose up agentbox # start API on :8080
110
+ docker compose run --rm test # run unit tests
111
+ ```
112
+
113
+ ## Configuration
114
+
115
+ | Variable | Default | Description |
116
+ |----------|---------|-------------|
117
+ | `AGENTBOX_HOST` | `0.0.0.0` | Bind host |
118
+ | `AGENTBOX_PORT` | `8080` | Bind port |
119
+ | `AGENTBOX_DEFAULT_TIMEOUT_SECONDS` | `30` | Execution timeout |
120
+ | `AGENTBOX_DEFAULT_MEMORY_MB` | unset | Optional default `RLIMIT_AS` cap |
121
+ | `AGENTBOX_SANDBOX_BACKEND` | `subprocess` | Backend selector |
122
+ | `AGENTBOX_SNAPSHOT_DIR` | `/tmp/agentbox-snapshots` | Workspace snapshot store |
123
+
124
+ ## Running tests
125
+
126
+ ```bash
127
+ pytest tests/ -v
128
+ ```
129
+
130
+ ## Roadmap
131
+
132
+ - [x] Node.js runtime + TypeScript client + per-run timeout
133
+ - [x] Filesystem snapshot/restore (tar workspaces)
134
+ - [x] `limits.memory_mb` via `RLIMIT_AS`
135
+ - [ ] gVisor runsc backend with warm pool
136
+ - [ ] Default-deny egress with allowlists (kernel netns)
137
+
138
+ ## License
139
+
140
+ MIT
141
+
142
+ ## Known limitations (v0.4)
143
+
144
+ - Subprocess sandbox only — **not production-grade isolation**
145
+ - `RLIMIT_AS` is a soft address-space cap, not a cgroup memory controller
146
+ - Credential stripping is not a network namespace
147
+ - Single-node, no warm pool
148
+ - TypeScript client is source-only (not published to npm)
@@ -0,0 +1,15 @@
1
+ # Security Policy
2
+
3
+ ## Reporting a vulnerability
4
+
5
+ Email **yash376351@gmail.com** with the repo name, a short description, and steps to reproduce. Please do not open a public issue for exploitable findings until we have had a reasonable chance to respond.
6
+
7
+ ## Threat model (honest)
8
+
9
+ agentbox executes **untrusted code** on your machine via a subprocess sandbox.
10
+
11
+ - The current backend is **subprocess + optional `RLIMIT_AS`**, not gVisor/Firecracker. Do **not** expose it to the public internet as-is.
12
+ - Credential stripping and timeouts reduce accidents; they are **not** a kernel isolation story.
13
+ - `limits.memory_mb` caps address space via `RLIMIT_AS` — it is not a cgroup memory controller and behavior differs by OS.
14
+ - Snapshots persist workspace files on disk under `AGENTBOX_SNAPSHOT_DIR`.
15
+ - Prefer running the API only on trusted networks, behind auth you add yourself.
@@ -0,0 +1,27 @@
1
+ services:
2
+ agentbox:
3
+ build:
4
+ context: .
5
+ dockerfile: docker/Dockerfile
6
+ target: runtime
7
+ ports:
8
+ - "8080:8080"
9
+ environment:
10
+ AGENTBOX_LOG_LEVEL: INFO
11
+ AGENTBOX_DEFAULT_TIMEOUT_SECONDS: 30
12
+ AGENTBOX_SNAPSHOT_DIR: /tmp/agentbox-snapshots
13
+ healthcheck:
14
+ test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health')"]
15
+ interval: 10s
16
+ timeout: 5s
17
+ retries: 3
18
+
19
+ test:
20
+ build:
21
+ context: .
22
+ dockerfile: docker/Dockerfile
23
+ target: dev
24
+ volumes:
25
+ - .:/app
26
+ working_dir: /app
27
+ command: ["pytest", "tests/", "-v"]
@@ -0,0 +1,19 @@
1
+ FROM python:3.12-slim AS base
2
+ WORKDIR /app
3
+ ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
4
+ RUN apt-get update && apt-get install -y --no-install-recommends nodejs && rm -rf /var/lib/apt/lists/*
5
+
6
+ FROM base AS dev
7
+ COPY pyproject.toml README.md ./
8
+ COPY src ./src
9
+ COPY tests ./tests
10
+ RUN pip install --no-cache-dir -e ".[dev]"
11
+ CMD ["pytest", "tests/", "-v"]
12
+
13
+ FROM base AS runtime
14
+ COPY pyproject.toml README.md ./
15
+ COPY src ./src
16
+ RUN pip install --no-cache-dir .
17
+ EXPOSE 8080
18
+ HEALTHCHECK CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health')"
19
+ CMD ["agentbox", "serve", "--host", "0.0.0.0", "--port", "8080"]
@@ -0,0 +1,6 @@
1
+ # agentbox — Planning Documents
2
+
3
+ | Document | Status | Description |
4
+ |----------|--------|-------------|
5
+ | [v0.1-completed-foundation.md](./v0.1-completed-foundation.md) | **Completed** | Initial foundation release |
6
+ | [v0.2-next-phase-roadmap.md](./v0.2-next-phase-roadmap.md) | **In Progress** | v0.2.0 shipped Node + timeouts + TS client; gVisor still open |