You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| matplotlib |`matplotlib`| Data visualization | networkx (transitive) |
121
+
122
+
#### Removed Libraries (Issue #5505)
123
+
124
+
The following libraries were removed as part of sandbox hardening. They are unnecessary for computation — their data processing features are covered by pandas, and they were designed to work with external resources (databases, networks, web servers) that are not available in the sandbox.
125
+
126
+
| Library | Reason for Removal |
127
+
| :-----: | :----------------- |
128
+
| duckdb | SQL database engine; covered by pandas |
129
+
| sqlalchemy | SQL toolkit/ORM; covered by pandas |
130
+
| bokeh | Visualization; unnecessary for computation |
131
+
| altair | Visualization; unnecessary for computation |
132
+
| cartopy | Map visualization; unnecessary for computation |
133
+
| seaborn | Visualization; unnecessary for computation |
134
+
135
+
### 5. Execution Modes
136
+
137
+
Guardian supports two execution modes for Python custom logic blocks, controlled by the `PYTHON_SANDBOX_MODE` environment variable.
138
+
139
+
#### Pyodide Mode (default)
140
+
141
+
The default mode runs Python code using Pyodide (CPython compiled to WebAssembly) inside a Node.js Worker Thread.
142
+
143
+
***No additional infrastructure required** — works out of the box
144
+
***Startup:** packages are pre-cached at policy-service startup for faster execution
145
+
***Limitation:** some C-extension packages (rasterio, rioxarray) are unavailable in WASM
146
+
147
+
**Configuration:** No env var needed (default), or explicitly set `PYTHON_SANDBOX_MODE=pyodide`
148
+
149
+
#### Docker Mode (experimental)
150
+
151
+
Runs Python code in an ephemeral Docker container using native CPython 3.12. Provides OS-level isolation.
2. Set the environment variable in policy-service configuration:
178
+
```
179
+
PYTHON_SANDBOX_MODE=docker
180
+
```
181
+
182
+
3. Ensure the policy-service container has Docker socket access. For docker-compose deployments, uncomment the Docker socket volume mount and the `python-sandbox` image build definition in the relevant compose file:
183
+
-`docker-compose-build.yml`, `docker-compose.yml`, `docker-compose-production.yml`, `docker-compose-production-build.yml`, `docker-compose-quickstart.yml` — uncomment the Docker socket volume and `python-sandbox` image build
184
+
185
+
{% hint style="warning" %}
186
+
Docker mode requires the Docker daemon to be available. The policy-service needs access to the Docker socket to spawn sandbox containers. For production deployments, consider using a Docker API proxy to restrict operations to sandbox container management only.
187
+
{% endhint %}
188
+
189
+
### 6. Sandbox Security
190
+
191
+
Python code in custom logic blocks runs in a sandboxed environment. The following restrictions are enforced:
***Pyodide mode** is suitable when users are trusted or semi-trusted. It blocks common attack vectors but is vulnerable to sophisticated Python introspection attacks.
231
+
***Docker mode** is suitable for untrusted code. OS-level isolation makes Python-level bypasses irrelevant — the container has no network, no host access, and is destroyed after execution.
232
+
{% endhint %}
233
+
234
+
### 7. Configuration Reference
235
+
236
+
| Environment Variable | Default | Description |
237
+
| :------------------- | :------ | :---------- |
238
+
|`PYTHON_SANDBOX_MODE`|`pyodide`| Execution mode: `pyodide` (default) or `docker`|
239
+
|`PYTHON_SANDBOX_TIMEOUT_MS`|`120000`| Execution timeout in milliseconds (both modes) |
240
+
|`PYTHON_SANDBOX_IMAGE`|`guardian/python-sandbox:latest`| Docker sandbox image name (Docker mode only) |
0 commit comments