@heimdall-ai/heimdall 0.1.0

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.
Files changed (67) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +471 -0
  3. package/dist/config/constants.d.ts +24 -0
  4. package/dist/config/constants.d.ts.map +1 -0
  5. package/dist/config/constants.js +70 -0
  6. package/dist/config/constants.js.map +1 -0
  7. package/dist/core/bash-manager.d.ts +56 -0
  8. package/dist/core/bash-manager.d.ts.map +1 -0
  9. package/dist/core/bash-manager.js +106 -0
  10. package/dist/core/bash-manager.js.map +1 -0
  11. package/dist/core/pyodide-manager.d.ts +125 -0
  12. package/dist/core/pyodide-manager.d.ts.map +1 -0
  13. package/dist/core/pyodide-manager.js +669 -0
  14. package/dist/core/pyodide-manager.js.map +1 -0
  15. package/dist/core/pyodide-worker.d.ts +9 -0
  16. package/dist/core/pyodide-worker.d.ts.map +1 -0
  17. package/dist/core/pyodide-worker.js +295 -0
  18. package/dist/core/pyodide-worker.js.map +1 -0
  19. package/dist/core/secure-fs.d.ts +101 -0
  20. package/dist/core/secure-fs.d.ts.map +1 -0
  21. package/dist/core/secure-fs.js +279 -0
  22. package/dist/core/secure-fs.js.map +1 -0
  23. package/dist/integration.test.d.ts +10 -0
  24. package/dist/integration.test.d.ts.map +1 -0
  25. package/dist/integration.test.js +439 -0
  26. package/dist/integration.test.js.map +1 -0
  27. package/dist/resources/index.d.ts +12 -0
  28. package/dist/resources/index.d.ts.map +1 -0
  29. package/dist/resources/index.js +13 -0
  30. package/dist/resources/index.js.map +1 -0
  31. package/dist/resources/workspace.d.ts +12 -0
  32. package/dist/resources/workspace.d.ts.map +1 -0
  33. package/dist/resources/workspace.js +105 -0
  34. package/dist/resources/workspace.js.map +1 -0
  35. package/dist/server.d.ts +17 -0
  36. package/dist/server.d.ts.map +1 -0
  37. package/dist/server.js +51 -0
  38. package/dist/server.js.map +1 -0
  39. package/dist/tools/bash-execution.d.ts +13 -0
  40. package/dist/tools/bash-execution.d.ts.map +1 -0
  41. package/dist/tools/bash-execution.js +135 -0
  42. package/dist/tools/bash-execution.js.map +1 -0
  43. package/dist/tools/filesystem.d.ts +12 -0
  44. package/dist/tools/filesystem.d.ts.map +1 -0
  45. package/dist/tools/filesystem.js +104 -0
  46. package/dist/tools/filesystem.js.map +1 -0
  47. package/dist/tools/index.d.ts +13 -0
  48. package/dist/tools/index.d.ts.map +1 -0
  49. package/dist/tools/index.js +17 -0
  50. package/dist/tools/index.js.map +1 -0
  51. package/dist/tools/python-execution.d.ts +12 -0
  52. package/dist/tools/python-execution.d.ts.map +1 -0
  53. package/dist/tools/python-execution.js +77 -0
  54. package/dist/tools/python-execution.js.map +1 -0
  55. package/dist/types/index.d.ts +64 -0
  56. package/dist/types/index.d.ts.map +1 -0
  57. package/dist/types/index.js +2 -0
  58. package/dist/types/index.js.map +1 -0
  59. package/dist/utils/async-lock.d.ts +35 -0
  60. package/dist/utils/async-lock.d.ts.map +1 -0
  61. package/dist/utils/async-lock.js +57 -0
  62. package/dist/utils/async-lock.js.map +1 -0
  63. package/dist/utils/index.d.ts +5 -0
  64. package/dist/utils/index.d.ts.map +1 -0
  65. package/dist/utils/index.js +5 -0
  66. package/dist/utils/index.js.map +1 -0
  67. package/package.json +61 -0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 Heimdall AI
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,471 @@
1
+ # Heimdall MCP Server
2
+
3
+ A TypeScript MCP server providing **sandboxed Python and Bash execution** using [Pyodide](https://pyodide.org/) (Python compiled to WebAssembly) and [just-bash](https://github.com/vercel-labs/just-bash).
4
+
5
+ > Named after the Norse god who guards the Bifröst bridge, Heimdall watches over code execution with security and vigilance.
6
+
7
+ ## Features
8
+
9
+ - 🔒 **Secure Sandbox**: Python code runs in an isolated WebAssembly environment
10
+ - 🐚 **Bash Execution**: Run bash commands with 50+ built-in tools (grep, sed, awk, jq, find, etc.)
11
+ - 📁 **Virtual Filesystem**: Read, write, list, and delete files in a persistent workspace
12
+ - 📦 **Package Management**: Install pure Python packages via micropip
13
+ - 🔄 **Session Persistence**: Workspace files persist across executions
14
+ - ⚡ **Native Integration**: Direct Pyodide and just-bash integration (no subprocess bridge)
15
+ - 🤝 **Interoperability**: Bash and Python share the same workspace filesystem
16
+
17
+ ## Architecture
18
+
19
+ ```
20
+ ┌──────────────────────────────────────────────────────────┐
21
+ │ MCP Client (Cursor) │
22
+ └────────────────────┬─────────────────────────────────────┘
23
+ │ MCP Protocol (stdio)
24
+ ┌────────────────────▼─────────────────────────────────────┐
25
+ │ TypeScript MCP Server (Node.js) │
26
+ │ • @modelcontextprotocol/sdk │
27
+ │ • PyodideManager + BashManager │
28
+ │ • Virtual FS ↔ Host FS sync │
29
+ ├──────────────────────┬──────────────────┬────────────────┤
30
+ │ Pyodide (WASM) │ just-bash (TS) │ Shared FS │
31
+ │ • Python runtime │ • Bash simulator│ • ./workspace │
32
+ │ • /workspace mount │ • 50+ commands │ • Persistence │
33
+ └──────────────────────┴──────────────────┴────────────────┘
34
+ ```
35
+
36
+ ## Prerequisites
37
+
38
+ - **Node.js** >= 18.0.0
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ npm install
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ### Development (with hot reload)
49
+
50
+ ```bash
51
+ npm run dev
52
+ ```
53
+
54
+ ### Production
55
+
56
+ ```bash
57
+ npm run build
58
+ npm start
59
+ ```
60
+
61
+ ### Cursor MCP Configuration
62
+
63
+ Add to your Cursor settings (`~/.cursor/mcp.json` or workspace `.cursor/mcp.json`):
64
+
65
+ ```json
66
+ {
67
+ "mcpServers": {
68
+ "heimdall": {
69
+ "command": "node",
70
+ "args": ["dist/server.js"],
71
+ "cwd": "/path/to/heimdall"
72
+ }
73
+ }
74
+ }
75
+ ```
76
+
77
+ Or for development with `tsx`:
78
+
79
+ ```json
80
+ {
81
+ "mcpServers": {
82
+ "heimdall": {
83
+ "command": "npx",
84
+ "args": ["tsx", "src/server.ts"],
85
+ "cwd": "/path/to/heimdall"
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ ## Available Tools
92
+
93
+ ### `execute_bash`
94
+
95
+ Execute bash commands in the Heimdall environment using just-bash.
96
+
97
+ **Features:**
98
+ - 50+ built-in commands: grep, sed, awk, find, jq, curl, tar, etc.
99
+ - Pipes and redirections: `|`, `>`, `>>`, `2>`, `2>&1`
100
+ - Variables, loops, conditionals, and functions
101
+ - File operations: ls, cat, cp, mv, rm, mkdir, etc.
102
+ - Text processing: grep, sed, awk, cut, sort, uniq, wc, etc.
103
+ - Data tools: jq (JSON), sqlite3 (SQLite), xan (CSV), yq (YAML)
104
+
105
+ **Security:**
106
+ - No real processes spawned (TypeScript simulation)
107
+ - Execution limits prevent infinite loops
108
+ - Network access disabled by default
109
+ - Filesystem limited to workspace directory
110
+
111
+ ```typescript
112
+ // Input
113
+ {
114
+ command: string; // Bash command to execute
115
+ cwd?: string; // Working directory (relative to /workspace)
116
+ }
117
+
118
+ // Output
119
+ {
120
+ stdout: string;
121
+ stderr: string;
122
+ exitCode: number;
123
+ }
124
+ ```
125
+
126
+ **Examples:**
127
+
128
+ ```bash
129
+ # Find Python files
130
+ find . -name "*.py" -type f
131
+
132
+ # Process text files
133
+ cat data.txt | grep "pattern" | wc -l
134
+
135
+ # JSON processing
136
+ cat data.json | jq '.users[] | {name, email}'
137
+
138
+ # Multiple commands
139
+ ls -la && cat README.md | head -10
140
+
141
+ # Text processing pipeline
142
+ grep -r "TODO" src/ | sort | uniq
143
+ ```
144
+
145
+ ### `execute_python`
146
+
147
+ Execute Python code in the sandbox. Packages are **auto-detected** from imports.
148
+
149
+ **Note:** Network access is NOT available - Pyodide runs in WebAssembly which provides a security boundary that prevents network requests.
150
+
151
+ ```typescript
152
+ // Input
153
+ {
154
+ code: string; // Python code to execute
155
+ packages?: string[]; // Optional additional packages (auto-detection handles most cases)
156
+ }
157
+
158
+ // Output
159
+ {
160
+ success: boolean;
161
+ stdout: string;
162
+ stderr: string;
163
+ result: string | null; // Last expression value
164
+ error: string | null;
165
+ }
166
+ ```
167
+
168
+ **Example:**
169
+ ```python
170
+ # Packages are auto-detected - no need to specify numpy/pandas!
171
+ import numpy as np
172
+ import pandas as pd
173
+
174
+ data = np.array([1, 2, 3, 4, 5])
175
+ df = pd.DataFrame({'values': data, 'squared': data ** 2})
176
+ print(df)
177
+ ```
178
+
179
+ ### `install_packages`
180
+
181
+ Install Python packages via micropip.
182
+
183
+ ```typescript
184
+ // Input
185
+ {
186
+ packages: string[]; // Package names to install
187
+ }
188
+
189
+ // Output
190
+ {
191
+ results: Array<{
192
+ package: string;
193
+ success: boolean;
194
+ error: string | null;
195
+ }>;
196
+ }
197
+ ```
198
+
199
+ ### `write_file`
200
+
201
+ Write content to a file in the workspace.
202
+
203
+ ```typescript
204
+ // Input
205
+ {
206
+ path: string; // File path relative to workspace
207
+ content: string; // Content to write
208
+ }
209
+ ```
210
+
211
+ ### `read_file`
212
+
213
+ Read a file from the workspace.
214
+
215
+ ```typescript
216
+ // Input
217
+ {
218
+ path: string; // File path relative to workspace
219
+ }
220
+ ```
221
+
222
+ ### `list_files`
223
+
224
+ List files in a directory.
225
+
226
+ ```typescript
227
+ // Input
228
+ {
229
+ path?: string; // Directory path (empty for root)
230
+ }
231
+
232
+ // Output
233
+ {
234
+ files: Array<{
235
+ name: string;
236
+ isDirectory: boolean;
237
+ size: number;
238
+ }>;
239
+ }
240
+ ```
241
+
242
+ ### `delete_file`
243
+
244
+ Delete a file or empty directory.
245
+
246
+ ```typescript
247
+ // Input
248
+ {
249
+ path: string; // File or directory path
250
+ }
251
+ ```
252
+
253
+ ## Available Resources
254
+
255
+ | URI | Description |
256
+ |-----|-------------|
257
+ | `workspace://files` | Tree listing of workspace contents |
258
+ | `workspace://file/{path}` | Read a specific file |
259
+ | `heimdall://info` | Environment information |
260
+
261
+ ## Workspace
262
+
263
+ Files are stored in the `workspace/` directory.
264
+
265
+ ### Configuration
266
+
267
+ Customize the server behavior with environment variables:
268
+
269
+ ```json
270
+ {
271
+ "mcpServers": {
272
+ "heimdall": {
273
+ "command": "node",
274
+ "args": ["dist/server.js"],
275
+ "cwd": "/path/to/heimdall",
276
+ "env": {
277
+ "HEIMDALL_WORKSPACE": "/custom/workspace/path",
278
+ "HEIMDALL_MAX_FILE_SIZE": "52428800",
279
+ "HEIMDALL_MAX_WORKSPACE_SIZE": "524288000",
280
+ "HEIMDALL_PYTHON_EXECUTION_TIMEOUT_MS": "5000"
281
+ }
282
+ }
283
+ }
284
+ }
285
+ ```
286
+
287
+ **Available environment variables:**
288
+
289
+ | Variable | Description | Default | Format |
290
+ |----------|-------------|---------|--------|
291
+ | `HEIMDALL_WORKSPACE` | Path to workspace directory | `./workspace` | Absolute or relative path |
292
+ | `HEIMDALL_MAX_FILE_SIZE` | Maximum size for a single file | `10485760` (10MB) | Bytes (positive integer) |
293
+ | `HEIMDALL_MAX_WORKSPACE_SIZE` | Maximum total workspace size | `104857600` (100MB) | Bytes (positive integer) |
294
+ | `HEIMDALL_PYTHON_EXECUTION_TIMEOUT_MS` | Python execution timeout | `5000` | Milliseconds (positive integer) |
295
+
296
+ **Example:** To allow 50MB files and 500MB total workspace:
297
+ - `HEIMDALL_MAX_FILE_SIZE`: `52428800` (50 * 1024 * 1024)
298
+ - `HEIMDALL_MAX_WORKSPACE_SIZE`: `524288000` (500 * 1024 * 1024)
299
+
300
+ ## Security
301
+
302
+ ### Network Access
303
+
304
+ **Python code cannot make network requests.** Pyodide runs in WebAssembly which provides a security boundary that prevents:
305
+ - HTTP/HTTPS requests from Python code
306
+ - Socket connections
307
+ - Any external network communication initiated by user code
308
+
309
+ This is enforced by the WASM runtime itself. Code that attempts to make network requests will fail with an error.
310
+
311
+ ### How Package Installation Works
312
+
313
+ Package installation (`micropip.install()`) works because it uses **Pyodide's internal mechanism** which operates at the JavaScript/Node.js layer, not Python:
314
+
315
+ ```
316
+ micropip.install("numpy") → Pyodide (JS) → Node.js fetch() → PyPI
317
+ ```
318
+
319
+ This is intentional - packages can be installed via Pyodide's trusted mechanism, but user code cannot make arbitrary network requests.
320
+
321
+ ### What Works vs What's Blocked
322
+
323
+ | ✅ Available | ❌ Blocked |
324
+ |-------------|-----------|
325
+ | Package installation (micropip) | `urllib.request.urlopen()` |
326
+ | File I/O (workspace) | `requests.get()` |
327
+ | Data processing (numpy, pandas) | Socket connections |
328
+ | URL parsing (`urllib.parse`) | External API calls |
329
+ | `loadPackagesFromImports()` | Data exfiltration |
330
+
331
+ ## Available Packages
332
+
333
+ Pyodide includes many popular packages:
334
+
335
+ ### Pre-installed
336
+ - Standard library (os, sys, json, re, math, etc.)
337
+ - micropip (for installing more packages)
338
+
339
+ ### Available via `install_packages`
340
+ - **Data Science**: numpy, pandas, scipy, scikit-learn
341
+ - **Visualization**: matplotlib, seaborn, plotly
342
+ - **HTML Parsing**: beautifulsoup4, lxml (parsing only, no fetching)
343
+ - **Text/NLP**: regex, nltk
344
+ - **Math**: sympy, statsmodels
345
+ - **Image**: pillow
346
+
347
+ ### Limitations
348
+ - **No network access** (WASM security boundary)
349
+ - Packages with native C/Fortran code must have Pyodide-compatible wheels
350
+ - No multiprocessing or threading
351
+ - Memory constrained by Node.js heap
352
+
353
+ See [Pyodide Packages](https://pyodide.org/en/stable/usage/packages-in-pyodide.html) for full compatibility list.
354
+
355
+ ## Project Structure
356
+
357
+ ```
358
+ heimdall/
359
+ ├── src/
360
+ │ ├── server.ts # Entry point
361
+ │ ├── config/
362
+ │ │ └── constants.ts # Configuration and limits
363
+ │ ├── core/
364
+ │ │ ├── bash-manager.ts # Bash execution (just-bash)
365
+ │ │ ├── pyodide-manager.ts # Python execution coordinator
366
+ │ │ ├── pyodide-worker.ts # Worker thread for Python
367
+ │ │ └── secure-fs.ts # Secure filesystem wrapper
368
+ │ ├── tools/
369
+ │ │ ├── bash-execution.ts # execute_bash tool
370
+ │ │ ├── python-execution.ts # execute_python tool
371
+ │ │ └── filesystem.ts # File operation tools
372
+ │ ├── resources/ # MCP resource handlers
373
+ │ ├── types/ # TypeScript interfaces
374
+ │ └── utils/ # Utilities (async-lock, etc.)
375
+ ├── test/ # Vitest tests
376
+ ├── dist/ # Compiled output
377
+ └── workspace/ # Persistent file storage
378
+ ```
379
+
380
+ ## Development
381
+
382
+ ### Build
383
+
384
+ ```bash
385
+ npm run build
386
+ ```
387
+
388
+ ### Test
389
+
390
+ ```bash
391
+ npm test # Run all tests
392
+ npm run test:watch # Watch mode
393
+ npm run test:coverage # With coverage
394
+ ```
395
+
396
+ ### Validate (before committing)
397
+
398
+ ```bash
399
+ npm run validate # Type-check + lint + format + build
400
+ ```
401
+
402
+ ### Clean
403
+
404
+ ```bash
405
+ npm run clean
406
+ ```
407
+
408
+ ## Bash and Python Interoperability
409
+
410
+ Bash and Python share the same workspace filesystem, enabling powerful workflows:
411
+
412
+ **Example: Bash prepares data, Python analyzes**
413
+
414
+ ```bash
415
+ # Bash: Extract and clean data
416
+ cat raw_data.csv | grep -v '^#' | sort > clean_data.csv
417
+ ```
418
+
419
+ ```python
420
+ # Python: Analyze the cleaned data
421
+ import pandas as pd
422
+ df = pd.read_csv('/workspace/clean_data.csv')
423
+ print(df.describe())
424
+ ```
425
+
426
+ **Example: Python generates data, Bash processes**
427
+
428
+ ```python
429
+ # Python: Generate report data
430
+ import json
431
+ data = [{"name": "Alice", "score": 95}, {"name": "Bob", "score": 87}]
432
+ with open('/workspace/results.json', 'w') as f:
433
+ json.dump(data, f)
434
+ ```
435
+
436
+ ```bash
437
+ # Bash: Extract specific fields
438
+ cat results.json | jq '.[] | select(.score > 90) | .name'
439
+ ```
440
+
441
+ ## Security Considerations
442
+
443
+ - ✅ Python runs in WebAssembly sandbox (memory-isolated)
444
+ - ✅ Bash uses just-bash (no real process spawning)
445
+ - ✅ No direct host filesystem access (only workspace)
446
+ - ✅ Execution limits prevent infinite loops and runaway scripts
447
+ - ✅ Limited networking capabilities
448
+ - ⚠️ Workspace files are accessible to all code executions
449
+ - ⚠️ Installed packages persist in the session
450
+
451
+ ## Troubleshooting
452
+
453
+ ### Slow first execution
454
+
455
+ Pyodide downloads ~15MB on first run. Subsequent runs use cached files.
456
+
457
+ ### Package installation fails
458
+
459
+ Some packages aren't available in Pyodide. Check compatibility at [pyodide.org](https://pyodide.org/en/stable/usage/packages-in-pyodide.html).
460
+
461
+ ### Memory errors
462
+
463
+ WebAssembly has memory limits. For large datasets, process in chunks. You can increase Node.js heap with:
464
+
465
+ ```bash
466
+ NODE_OPTIONS="--max-old-space-size=4096" npm start
467
+ ```
468
+
469
+ ## License
470
+
471
+ MIT
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Host filesystem path to workspace directory
3
+ */
4
+ export declare const WORKSPACE_DIR: string;
5
+ /**
6
+ * Virtual filesystem path to workspace directory in Pyodide
7
+ */
8
+ export declare const VIRTUAL_WORKSPACE = "/workspace";
9
+ /**
10
+ * Maximum size for a single file (default: 10MB)
11
+ * Configure via HEIMDALL_MAX_FILE_SIZE environment variable (in bytes)
12
+ */
13
+ export declare const MAX_FILE_SIZE: number;
14
+ /**
15
+ * Maximum total workspace size (default: 100MB)
16
+ * Configure via HEIMDALL_MAX_WORKSPACE_SIZE environment variable (in bytes)
17
+ */
18
+ export declare const MAX_WORKSPACE_SIZE: number;
19
+ /**
20
+ * Maximum execution time for Python code (default: 5000ms)
21
+ * Configure via HEIMDALL_PYTHON_EXECUTION_TIMEOUT_MS environment variable
22
+ */
23
+ export declare const PYTHON_EXECUTION_TIMEOUT_MS: number;
24
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/config/constants.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,eAAO,MAAM,aAAa,QACuD,CAAC;AAElF;;GAEG;AACH,eAAO,MAAM,iBAAiB,eAAe,CAAC;AAkD9C;;;GAGG;AACH,eAAO,MAAM,aAAa,QAIzB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAI9B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,2BAA2B,QAIvC,CAAC"}