gitx.do 0.1.1 → 0.1.3

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 (376) hide show
  1. package/README.md +40 -353
  2. package/dist/do/logger.d.ts +50 -0
  3. package/dist/do/logger.d.ts.map +1 -0
  4. package/dist/do/logger.js +122 -0
  5. package/dist/do/logger.js.map +1 -0
  6. package/dist/{durable-object → do}/schema.d.ts +3 -3
  7. package/dist/do/schema.d.ts.map +1 -0
  8. package/dist/{durable-object → do}/schema.js +4 -3
  9. package/dist/do/schema.js.map +1 -0
  10. package/dist/do/types.d.ts +267 -0
  11. package/dist/do/types.d.ts.map +1 -0
  12. package/dist/do/types.js +62 -0
  13. package/dist/do/types.js.map +1 -0
  14. package/dist/index.d.ts +15 -469
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +39 -481
  17. package/dist/index.js.map +1 -1
  18. package/dist/mcp/auth.d.ts +77 -0
  19. package/dist/mcp/auth.d.ts.map +1 -0
  20. package/dist/mcp/auth.js +278 -0
  21. package/dist/mcp/auth.js.map +1 -0
  22. package/dist/mcp/index.d.ts +13 -0
  23. package/dist/mcp/index.d.ts.map +1 -0
  24. package/dist/mcp/index.js +19 -0
  25. package/dist/mcp/index.js.map +1 -0
  26. package/dist/mcp/server.d.ts +200 -0
  27. package/dist/mcp/server.d.ts.map +1 -0
  28. package/dist/mcp/server.js +275 -0
  29. package/dist/mcp/server.js.map +1 -0
  30. package/dist/mcp/tool-registry.d.ts +47 -0
  31. package/dist/mcp/tool-registry.d.ts.map +1 -0
  32. package/dist/mcp/tool-registry.js +284 -0
  33. package/dist/mcp/tool-registry.js.map +1 -0
  34. package/dist/mcp/tools.d.ts +103 -515
  35. package/dist/mcp/tools.d.ts.map +1 -1
  36. package/dist/mcp/tools.js +676 -3087
  37. package/dist/mcp/tools.js.map +1 -1
  38. package/dist/mcp/types.d.ts +124 -0
  39. package/dist/mcp/types.d.ts.map +1 -0
  40. package/dist/mcp/types.js +9 -0
  41. package/dist/mcp/types.js.map +1 -0
  42. package/package.json +19 -21
  43. package/dist/cli/commands/add.d.ts +0 -176
  44. package/dist/cli/commands/add.d.ts.map +0 -1
  45. package/dist/cli/commands/add.js +0 -979
  46. package/dist/cli/commands/add.js.map +0 -1
  47. package/dist/cli/commands/blame.d.ts +0 -259
  48. package/dist/cli/commands/blame.d.ts.map +0 -1
  49. package/dist/cli/commands/blame.js +0 -609
  50. package/dist/cli/commands/blame.js.map +0 -1
  51. package/dist/cli/commands/branch.d.ts +0 -249
  52. package/dist/cli/commands/branch.d.ts.map +0 -1
  53. package/dist/cli/commands/branch.js +0 -693
  54. package/dist/cli/commands/branch.js.map +0 -1
  55. package/dist/cli/commands/checkout.d.ts +0 -73
  56. package/dist/cli/commands/checkout.d.ts.map +0 -1
  57. package/dist/cli/commands/checkout.js +0 -725
  58. package/dist/cli/commands/checkout.js.map +0 -1
  59. package/dist/cli/commands/commit.d.ts +0 -182
  60. package/dist/cli/commands/commit.d.ts.map +0 -1
  61. package/dist/cli/commands/commit.js +0 -457
  62. package/dist/cli/commands/commit.js.map +0 -1
  63. package/dist/cli/commands/diff.d.ts +0 -464
  64. package/dist/cli/commands/diff.d.ts.map +0 -1
  65. package/dist/cli/commands/diff.js +0 -959
  66. package/dist/cli/commands/diff.js.map +0 -1
  67. package/dist/cli/commands/log.d.ts +0 -239
  68. package/dist/cli/commands/log.d.ts.map +0 -1
  69. package/dist/cli/commands/log.js +0 -535
  70. package/dist/cli/commands/log.js.map +0 -1
  71. package/dist/cli/commands/merge.d.ts +0 -106
  72. package/dist/cli/commands/merge.d.ts.map +0 -1
  73. package/dist/cli/commands/merge.js +0 -852
  74. package/dist/cli/commands/merge.js.map +0 -1
  75. package/dist/cli/commands/review.d.ts +0 -457
  76. package/dist/cli/commands/review.d.ts.map +0 -1
  77. package/dist/cli/commands/review.js +0 -558
  78. package/dist/cli/commands/review.js.map +0 -1
  79. package/dist/cli/commands/stash.d.ts +0 -157
  80. package/dist/cli/commands/stash.d.ts.map +0 -1
  81. package/dist/cli/commands/stash.js +0 -655
  82. package/dist/cli/commands/stash.js.map +0 -1
  83. package/dist/cli/commands/status.d.ts +0 -269
  84. package/dist/cli/commands/status.d.ts.map +0 -1
  85. package/dist/cli/commands/status.js +0 -492
  86. package/dist/cli/commands/status.js.map +0 -1
  87. package/dist/cli/commands/web.d.ts +0 -199
  88. package/dist/cli/commands/web.d.ts.map +0 -1
  89. package/dist/cli/commands/web.js +0 -697
  90. package/dist/cli/commands/web.js.map +0 -1
  91. package/dist/cli/fs-adapter.d.ts +0 -656
  92. package/dist/cli/fs-adapter.d.ts.map +0 -1
  93. package/dist/cli/fs-adapter.js +0 -1177
  94. package/dist/cli/fs-adapter.js.map +0 -1
  95. package/dist/cli/fsx-cli-adapter.d.ts +0 -359
  96. package/dist/cli/fsx-cli-adapter.d.ts.map +0 -1
  97. package/dist/cli/fsx-cli-adapter.js +0 -619
  98. package/dist/cli/fsx-cli-adapter.js.map +0 -1
  99. package/dist/cli/index.d.ts +0 -387
  100. package/dist/cli/index.d.ts.map +0 -1
  101. package/dist/cli/index.js +0 -579
  102. package/dist/cli/index.js.map +0 -1
  103. package/dist/cli/ui/components/DiffView.d.ts +0 -12
  104. package/dist/cli/ui/components/DiffView.d.ts.map +0 -1
  105. package/dist/cli/ui/components/DiffView.js +0 -11
  106. package/dist/cli/ui/components/DiffView.js.map +0 -1
  107. package/dist/cli/ui/components/ErrorDisplay.d.ts +0 -10
  108. package/dist/cli/ui/components/ErrorDisplay.d.ts.map +0 -1
  109. package/dist/cli/ui/components/ErrorDisplay.js +0 -11
  110. package/dist/cli/ui/components/ErrorDisplay.js.map +0 -1
  111. package/dist/cli/ui/components/FuzzySearch.d.ts +0 -15
  112. package/dist/cli/ui/components/FuzzySearch.d.ts.map +0 -1
  113. package/dist/cli/ui/components/FuzzySearch.js +0 -12
  114. package/dist/cli/ui/components/FuzzySearch.js.map +0 -1
  115. package/dist/cli/ui/components/LoadingSpinner.d.ts +0 -10
  116. package/dist/cli/ui/components/LoadingSpinner.d.ts.map +0 -1
  117. package/dist/cli/ui/components/LoadingSpinner.js +0 -10
  118. package/dist/cli/ui/components/LoadingSpinner.js.map +0 -1
  119. package/dist/cli/ui/components/NavigationList.d.ts +0 -14
  120. package/dist/cli/ui/components/NavigationList.d.ts.map +0 -1
  121. package/dist/cli/ui/components/NavigationList.js +0 -11
  122. package/dist/cli/ui/components/NavigationList.js.map +0 -1
  123. package/dist/cli/ui/components/ScrollableContent.d.ts +0 -13
  124. package/dist/cli/ui/components/ScrollableContent.d.ts.map +0 -1
  125. package/dist/cli/ui/components/ScrollableContent.js +0 -11
  126. package/dist/cli/ui/components/ScrollableContent.js.map +0 -1
  127. package/dist/cli/ui/components/index.d.ts +0 -7
  128. package/dist/cli/ui/components/index.d.ts.map +0 -1
  129. package/dist/cli/ui/components/index.js +0 -9
  130. package/dist/cli/ui/components/index.js.map +0 -1
  131. package/dist/cli/ui/terminal-ui.d.ts +0 -85
  132. package/dist/cli/ui/terminal-ui.d.ts.map +0 -1
  133. package/dist/cli/ui/terminal-ui.js +0 -121
  134. package/dist/cli/ui/terminal-ui.js.map +0 -1
  135. package/dist/do/BashModule.d.ts +0 -871
  136. package/dist/do/BashModule.d.ts.map +0 -1
  137. package/dist/do/BashModule.js +0 -1143
  138. package/dist/do/BashModule.js.map +0 -1
  139. package/dist/do/FsModule.d.ts +0 -612
  140. package/dist/do/FsModule.d.ts.map +0 -1
  141. package/dist/do/FsModule.js +0 -1120
  142. package/dist/do/FsModule.js.map +0 -1
  143. package/dist/do/GitModule.d.ts +0 -635
  144. package/dist/do/GitModule.d.ts.map +0 -1
  145. package/dist/do/GitModule.js +0 -784
  146. package/dist/do/GitModule.js.map +0 -1
  147. package/dist/do/GitRepoDO.d.ts +0 -281
  148. package/dist/do/GitRepoDO.d.ts.map +0 -1
  149. package/dist/do/GitRepoDO.js +0 -479
  150. package/dist/do/GitRepoDO.js.map +0 -1
  151. package/dist/do/bash-ast.d.ts +0 -246
  152. package/dist/do/bash-ast.d.ts.map +0 -1
  153. package/dist/do/bash-ast.js +0 -888
  154. package/dist/do/bash-ast.js.map +0 -1
  155. package/dist/do/container-executor.d.ts +0 -491
  156. package/dist/do/container-executor.d.ts.map +0 -1
  157. package/dist/do/container-executor.js +0 -731
  158. package/dist/do/container-executor.js.map +0 -1
  159. package/dist/do/index.d.ts +0 -53
  160. package/dist/do/index.d.ts.map +0 -1
  161. package/dist/do/index.js +0 -91
  162. package/dist/do/index.js.map +0 -1
  163. package/dist/do/tiered-storage.d.ts +0 -403
  164. package/dist/do/tiered-storage.d.ts.map +0 -1
  165. package/dist/do/tiered-storage.js +0 -689
  166. package/dist/do/tiered-storage.js.map +0 -1
  167. package/dist/do/withBash.d.ts +0 -231
  168. package/dist/do/withBash.d.ts.map +0 -1
  169. package/dist/do/withBash.js +0 -244
  170. package/dist/do/withBash.js.map +0 -1
  171. package/dist/do/withFs.d.ts +0 -237
  172. package/dist/do/withFs.d.ts.map +0 -1
  173. package/dist/do/withFs.js +0 -387
  174. package/dist/do/withFs.js.map +0 -1
  175. package/dist/do/withGit.d.ts +0 -180
  176. package/dist/do/withGit.d.ts.map +0 -1
  177. package/dist/do/withGit.js +0 -271
  178. package/dist/do/withGit.js.map +0 -1
  179. package/dist/durable-object/object-store.d.ts +0 -633
  180. package/dist/durable-object/object-store.d.ts.map +0 -1
  181. package/dist/durable-object/object-store.js +0 -1164
  182. package/dist/durable-object/object-store.js.map +0 -1
  183. package/dist/durable-object/schema.d.ts.map +0 -1
  184. package/dist/durable-object/schema.js.map +0 -1
  185. package/dist/durable-object/wal.d.ts +0 -416
  186. package/dist/durable-object/wal.d.ts.map +0 -1
  187. package/dist/durable-object/wal.js +0 -445
  188. package/dist/durable-object/wal.js.map +0 -1
  189. package/dist/mcp/adapter.d.ts +0 -772
  190. package/dist/mcp/adapter.d.ts.map +0 -1
  191. package/dist/mcp/adapter.js +0 -895
  192. package/dist/mcp/adapter.js.map +0 -1
  193. package/dist/mcp/sandbox/miniflare-evaluator.d.ts +0 -22
  194. package/dist/mcp/sandbox/miniflare-evaluator.d.ts.map +0 -1
  195. package/dist/mcp/sandbox/miniflare-evaluator.js +0 -140
  196. package/dist/mcp/sandbox/miniflare-evaluator.js.map +0 -1
  197. package/dist/mcp/sandbox/object-store-proxy.d.ts +0 -32
  198. package/dist/mcp/sandbox/object-store-proxy.d.ts.map +0 -1
  199. package/dist/mcp/sandbox/object-store-proxy.js +0 -30
  200. package/dist/mcp/sandbox/object-store-proxy.js.map +0 -1
  201. package/dist/mcp/sandbox/template.d.ts +0 -17
  202. package/dist/mcp/sandbox/template.d.ts.map +0 -1
  203. package/dist/mcp/sandbox/template.js +0 -71
  204. package/dist/mcp/sandbox/template.js.map +0 -1
  205. package/dist/mcp/sandbox.d.ts +0 -764
  206. package/dist/mcp/sandbox.d.ts.map +0 -1
  207. package/dist/mcp/sandbox.js +0 -1362
  208. package/dist/mcp/sandbox.js.map +0 -1
  209. package/dist/mcp/sdk-adapter.d.ts +0 -835
  210. package/dist/mcp/sdk-adapter.d.ts.map +0 -1
  211. package/dist/mcp/sdk-adapter.js +0 -974
  212. package/dist/mcp/sdk-adapter.js.map +0 -1
  213. package/dist/mcp/tools/do.d.ts +0 -32
  214. package/dist/mcp/tools/do.d.ts.map +0 -1
  215. package/dist/mcp/tools/do.js +0 -117
  216. package/dist/mcp/tools/do.js.map +0 -1
  217. package/dist/ops/blame.d.ts +0 -551
  218. package/dist/ops/blame.d.ts.map +0 -1
  219. package/dist/ops/blame.js +0 -1037
  220. package/dist/ops/blame.js.map +0 -1
  221. package/dist/ops/branch.d.ts +0 -766
  222. package/dist/ops/branch.d.ts.map +0 -1
  223. package/dist/ops/branch.js +0 -950
  224. package/dist/ops/branch.js.map +0 -1
  225. package/dist/ops/commit-traversal.d.ts +0 -349
  226. package/dist/ops/commit-traversal.d.ts.map +0 -1
  227. package/dist/ops/commit-traversal.js +0 -821
  228. package/dist/ops/commit-traversal.js.map +0 -1
  229. package/dist/ops/commit.d.ts +0 -555
  230. package/dist/ops/commit.d.ts.map +0 -1
  231. package/dist/ops/commit.js +0 -826
  232. package/dist/ops/commit.js.map +0 -1
  233. package/dist/ops/merge-base.d.ts +0 -397
  234. package/dist/ops/merge-base.d.ts.map +0 -1
  235. package/dist/ops/merge-base.js +0 -691
  236. package/dist/ops/merge-base.js.map +0 -1
  237. package/dist/ops/merge.d.ts +0 -855
  238. package/dist/ops/merge.d.ts.map +0 -1
  239. package/dist/ops/merge.js +0 -1551
  240. package/dist/ops/merge.js.map +0 -1
  241. package/dist/ops/tag.d.ts +0 -247
  242. package/dist/ops/tag.d.ts.map +0 -1
  243. package/dist/ops/tag.js +0 -649
  244. package/dist/ops/tag.js.map +0 -1
  245. package/dist/ops/tree-builder.d.ts +0 -178
  246. package/dist/ops/tree-builder.d.ts.map +0 -1
  247. package/dist/ops/tree-builder.js +0 -271
  248. package/dist/ops/tree-builder.js.map +0 -1
  249. package/dist/ops/tree-diff.d.ts +0 -291
  250. package/dist/ops/tree-diff.d.ts.map +0 -1
  251. package/dist/ops/tree-diff.js +0 -705
  252. package/dist/ops/tree-diff.js.map +0 -1
  253. package/dist/pack/delta.d.ts +0 -248
  254. package/dist/pack/delta.d.ts.map +0 -1
  255. package/dist/pack/delta.js +0 -740
  256. package/dist/pack/delta.js.map +0 -1
  257. package/dist/pack/format.d.ts +0 -446
  258. package/dist/pack/format.d.ts.map +0 -1
  259. package/dist/pack/format.js +0 -572
  260. package/dist/pack/format.js.map +0 -1
  261. package/dist/pack/full-generation.d.ts +0 -612
  262. package/dist/pack/full-generation.d.ts.map +0 -1
  263. package/dist/pack/full-generation.js +0 -1378
  264. package/dist/pack/full-generation.js.map +0 -1
  265. package/dist/pack/generation.d.ts +0 -441
  266. package/dist/pack/generation.d.ts.map +0 -1
  267. package/dist/pack/generation.js +0 -707
  268. package/dist/pack/generation.js.map +0 -1
  269. package/dist/pack/index.d.ts +0 -502
  270. package/dist/pack/index.d.ts.map +0 -1
  271. package/dist/pack/index.js +0 -833
  272. package/dist/pack/index.js.map +0 -1
  273. package/dist/refs/branch.d.ts +0 -683
  274. package/dist/refs/branch.d.ts.map +0 -1
  275. package/dist/refs/branch.js +0 -881
  276. package/dist/refs/branch.js.map +0 -1
  277. package/dist/refs/storage.d.ts +0 -833
  278. package/dist/refs/storage.d.ts.map +0 -1
  279. package/dist/refs/storage.js +0 -1023
  280. package/dist/refs/storage.js.map +0 -1
  281. package/dist/refs/tag.d.ts +0 -860
  282. package/dist/refs/tag.d.ts.map +0 -1
  283. package/dist/refs/tag.js +0 -996
  284. package/dist/refs/tag.js.map +0 -1
  285. package/dist/storage/backend.d.ts +0 -425
  286. package/dist/storage/backend.d.ts.map +0 -1
  287. package/dist/storage/backend.js +0 -41
  288. package/dist/storage/backend.js.map +0 -1
  289. package/dist/storage/fsx-adapter.d.ts +0 -204
  290. package/dist/storage/fsx-adapter.d.ts.map +0 -1
  291. package/dist/storage/fsx-adapter.js +0 -518
  292. package/dist/storage/fsx-adapter.js.map +0 -1
  293. package/dist/storage/lru-cache.d.ts +0 -691
  294. package/dist/storage/lru-cache.d.ts.map +0 -1
  295. package/dist/storage/lru-cache.js +0 -813
  296. package/dist/storage/lru-cache.js.map +0 -1
  297. package/dist/storage/object-index.d.ts +0 -585
  298. package/dist/storage/object-index.d.ts.map +0 -1
  299. package/dist/storage/object-index.js +0 -532
  300. package/dist/storage/object-index.js.map +0 -1
  301. package/dist/storage/r2-pack.d.ts +0 -1257
  302. package/dist/storage/r2-pack.d.ts.map +0 -1
  303. package/dist/storage/r2-pack.js +0 -1773
  304. package/dist/storage/r2-pack.js.map +0 -1
  305. package/dist/tiered/cdc-pipeline.d.ts +0 -1888
  306. package/dist/tiered/cdc-pipeline.d.ts.map +0 -1
  307. package/dist/tiered/cdc-pipeline.js +0 -1880
  308. package/dist/tiered/cdc-pipeline.js.map +0 -1
  309. package/dist/tiered/migration.d.ts +0 -1104
  310. package/dist/tiered/migration.d.ts.map +0 -1
  311. package/dist/tiered/migration.js +0 -1217
  312. package/dist/tiered/migration.js.map +0 -1
  313. package/dist/tiered/parquet-writer.d.ts +0 -1145
  314. package/dist/tiered/parquet-writer.d.ts.map +0 -1
  315. package/dist/tiered/parquet-writer.js +0 -1183
  316. package/dist/tiered/parquet-writer.js.map +0 -1
  317. package/dist/tiered/read-path.d.ts +0 -835
  318. package/dist/tiered/read-path.d.ts.map +0 -1
  319. package/dist/tiered/read-path.js +0 -487
  320. package/dist/tiered/read-path.js.map +0 -1
  321. package/dist/types/capability.d.ts +0 -1385
  322. package/dist/types/capability.d.ts.map +0 -1
  323. package/dist/types/capability.js +0 -36
  324. package/dist/types/capability.js.map +0 -1
  325. package/dist/types/index.d.ts +0 -13
  326. package/dist/types/index.d.ts.map +0 -1
  327. package/dist/types/index.js +0 -18
  328. package/dist/types/index.js.map +0 -1
  329. package/dist/types/interfaces.d.ts +0 -673
  330. package/dist/types/interfaces.d.ts.map +0 -1
  331. package/dist/types/interfaces.js +0 -26
  332. package/dist/types/interfaces.js.map +0 -1
  333. package/dist/types/objects.d.ts +0 -692
  334. package/dist/types/objects.d.ts.map +0 -1
  335. package/dist/types/objects.js +0 -837
  336. package/dist/types/objects.js.map +0 -1
  337. package/dist/types/storage.d.ts +0 -603
  338. package/dist/types/storage.d.ts.map +0 -1
  339. package/dist/types/storage.js +0 -191
  340. package/dist/types/storage.js.map +0 -1
  341. package/dist/types/worker-loader.d.ts +0 -60
  342. package/dist/types/worker-loader.d.ts.map +0 -1
  343. package/dist/types/worker-loader.js +0 -62
  344. package/dist/types/worker-loader.js.map +0 -1
  345. package/dist/utils/hash.d.ts +0 -198
  346. package/dist/utils/hash.d.ts.map +0 -1
  347. package/dist/utils/hash.js +0 -272
  348. package/dist/utils/hash.js.map +0 -1
  349. package/dist/utils/sha1.d.ts +0 -325
  350. package/dist/utils/sha1.d.ts.map +0 -1
  351. package/dist/utils/sha1.js +0 -635
  352. package/dist/utils/sha1.js.map +0 -1
  353. package/dist/wire/capabilities.d.ts +0 -1044
  354. package/dist/wire/capabilities.d.ts.map +0 -1
  355. package/dist/wire/capabilities.js +0 -941
  356. package/dist/wire/capabilities.js.map +0 -1
  357. package/dist/wire/path-security.d.ts +0 -157
  358. package/dist/wire/path-security.d.ts.map +0 -1
  359. package/dist/wire/path-security.js +0 -307
  360. package/dist/wire/path-security.js.map +0 -1
  361. package/dist/wire/pkt-line.d.ts +0 -345
  362. package/dist/wire/pkt-line.d.ts.map +0 -1
  363. package/dist/wire/pkt-line.js +0 -381
  364. package/dist/wire/pkt-line.js.map +0 -1
  365. package/dist/wire/receive-pack.d.ts +0 -1059
  366. package/dist/wire/receive-pack.d.ts.map +0 -1
  367. package/dist/wire/receive-pack.js +0 -1414
  368. package/dist/wire/receive-pack.js.map +0 -1
  369. package/dist/wire/smart-http.d.ts +0 -799
  370. package/dist/wire/smart-http.d.ts.map +0 -1
  371. package/dist/wire/smart-http.js +0 -945
  372. package/dist/wire/smart-http.js.map +0 -1
  373. package/dist/wire/upload-pack.d.ts +0 -727
  374. package/dist/wire/upload-pack.d.ts.map +0 -1
  375. package/dist/wire/upload-pack.js +0 -1141
  376. package/dist/wire/upload-pack.js.map +0 -1
@@ -1,764 +0,0 @@
1
- /**
2
- * @fileoverview MCP Sandbox Execution Environment
3
- *
4
- * Provides an isolated execution environment for MCP tools with:
5
- * - Resource limits (memory, CPU, time, file descriptors, disk)
6
- * - Capability restrictions (file read/write, network, process spawning)
7
- * - Safe git operation execution with permission checks
8
- * - Audit logging for security violations
9
- *
10
- * SECURITY: Uses Node.js vm module concepts for proper isolation. The sandbox
11
- * implements multi-layer security through:
12
- * 1. Pre-execution static analysis to detect dangerous patterns
13
- * 2. Runtime permission checks via Proxy-based module interception
14
- * 3. Resource limit enforcement during execution
15
- * 4. Permission violation recording for audit trails
16
- *
17
- * @module mcp/sandbox
18
- *
19
- * @example
20
- * // Create a sandbox with limited permissions
21
- * import { createSandbox, SandboxState } from './sandbox'
22
- *
23
- * const sandbox = createSandbox({
24
- * timeout: 5000,
25
- * memoryLimit: 128 * 1024 * 1024,
26
- * permissions: {
27
- * fileRead: true,
28
- * fileWrite: false,
29
- * network: false,
30
- * spawn: false
31
- * }
32
- * })
33
- *
34
- * await sandbox.start()
35
- * const result = await sandbox.execute(() => {
36
- * return 'Hello from sandbox!'
37
- * })
38
- *
39
- * if (result.error) {
40
- * console.error('Execution failed:', result.error.message)
41
- * } else {
42
- * console.log('Result:', result.value)
43
- * }
44
- *
45
- * await sandbox.destroy()
46
- *
47
- * @example
48
- * // Using a sandbox pool for concurrent execution
49
- * import { createSandboxPool } from './sandbox'
50
- *
51
- * const pool = createSandboxPool({ size: 4 })
52
- * const sandbox = await pool.acquire()
53
- *
54
- * try {
55
- * const result = await sandbox.execute(myFunction)
56
- * } finally {
57
- * await pool.release(sandbox)
58
- * }
59
- *
60
- * await pool.shutdown()
61
- */
62
- import { EventEmitter } from 'events';
63
- /**
64
- * Sandbox error codes.
65
- *
66
- * @description
67
- * Enumeration of all possible error codes that can be returned by sandbox
68
- * operations. These codes indicate the specific reason for execution failure.
69
- *
70
- * @enum {string}
71
- */
72
- export declare enum SandboxErrorCode {
73
- /** Execution exceeded the configured timeout */
74
- TIMEOUT = "TIMEOUT",
75
- /** Memory usage exceeded the configured limit */
76
- MEMORY_LIMIT_EXCEEDED = "MEMORY_LIMIT_EXCEEDED",
77
- /** CPU time exceeded the configured limit */
78
- CPU_LIMIT_EXCEEDED = "CPU_LIMIT_EXCEEDED",
79
- /** Operation was denied due to insufficient permissions */
80
- PERMISSION_DENIED = "PERMISSION_DENIED",
81
- /** General execution error occurred */
82
- EXECUTION_ERROR = "EXECUTION_ERROR",
83
- /** Too many file descriptors opened */
84
- FILE_DESCRIPTOR_LIMIT = "FILE_DESCRIPTOR_LIMIT",
85
- /** Too many processes spawned */
86
- PROCESS_LIMIT_EXCEEDED = "PROCESS_LIMIT_EXCEEDED",
87
- /** Network bandwidth limit exceeded */
88
- BANDWIDTH_LIMIT_EXCEEDED = "BANDWIDTH_LIMIT_EXCEEDED",
89
- /** Disk write limit exceeded */
90
- DISK_LIMIT_EXCEEDED = "DISK_LIMIT_EXCEEDED",
91
- /** Sandbox crashed unexpectedly */
92
- SANDBOX_CRASHED = "SANDBOX_CRASHED",
93
- /** Sandbox is paused and not accepting executions */
94
- SANDBOX_PAUSED = "SANDBOX_PAUSED"
95
- }
96
- /**
97
- * Sandbox error class.
98
- *
99
- * @description
100
- * Custom error class for sandbox-specific errors. Includes an error code
101
- * for programmatic handling and optional additional data.
102
- *
103
- * @class SandboxError
104
- * @extends Error
105
- *
106
- * @example
107
- * try {
108
- * await sandbox.execute(fn)
109
- * } catch (error) {
110
- * if (error instanceof SandboxError) {
111
- * console.log('Error code:', error.code)
112
- * console.log('Error data:', error.data)
113
- * }
114
- * }
115
- */
116
- export declare class SandboxError extends Error {
117
- /** The error code identifying the type of error */
118
- code: SandboxErrorCode;
119
- /** Optional additional error data */
120
- data?: Record<string, unknown>;
121
- /** Stack trace (inherited from Error) */
122
- stack?: string;
123
- /**
124
- * Create a new sandbox error.
125
- * @param code - The error code
126
- * @param message - Human-readable error message
127
- * @param data - Optional additional error data
128
- */
129
- constructor(code: SandboxErrorCode, message: string, data?: Record<string, unknown>);
130
- /**
131
- * Convert error to JSON representation.
132
- * @returns JSON-serializable error object
133
- */
134
- toJSON(): {
135
- code: SandboxErrorCode;
136
- message: string;
137
- data?: Record<string, unknown>;
138
- };
139
- }
140
- /**
141
- * Sandbox state enum.
142
- *
143
- * @description
144
- * Represents the lifecycle state of a sandbox instance.
145
- *
146
- * @enum {string}
147
- */
148
- export declare enum SandboxState {
149
- /** Sandbox is idle and ready for use */
150
- IDLE = "IDLE",
151
- /** Sandbox is currently executing code */
152
- RUNNING = "RUNNING",
153
- /** Sandbox is paused (can be resumed) */
154
- PAUSED = "PAUSED",
155
- /** Sandbox has been destroyed and cannot be reused */
156
- DESTROYED = "DESTROYED"
157
- }
158
- /**
159
- * Isolation level for sandbox.
160
- *
161
- * @description
162
- * Determines how strictly the sandbox enforces isolation:
163
- * - 'strict': Most restrictive, blocks native modules
164
- * - 'normal': Default, balanced security
165
- * - 'lax': Least restrictive
166
- *
167
- * @typedef {'strict' | 'normal' | 'lax'} IsolationLevel
168
- */
169
- export type IsolationLevel = 'strict' | 'normal' | 'lax';
170
- /**
171
- * Resource limits configuration.
172
- *
173
- * @description
174
- * Defines limits on system resources that the sandbox can consume.
175
- *
176
- * @interface ResourceLimits
177
- */
178
- export interface ResourceLimits {
179
- /** Maximum memory usage in bytes */
180
- memoryLimit?: number;
181
- /** Maximum CPU time in milliseconds */
182
- cpuTimeLimit?: number;
183
- /** Maximum number of open file handles */
184
- maxOpenFiles?: number;
185
- /** Maximum number of spawned processes */
186
- maxProcesses?: number;
187
- /** Maximum network bandwidth in bytes/second */
188
- networkBandwidthLimit?: number;
189
- /** Maximum disk write in bytes */
190
- diskWriteLimit?: number;
191
- }
192
- /**
193
- * Permission set for sandbox.
194
- *
195
- * @description
196
- * Defines what operations are allowed within the sandbox.
197
- *
198
- * @interface PermissionSet
199
- *
200
- * @example
201
- * const permissions: PermissionSet = {
202
- * fileRead: true,
203
- * fileWrite: false,
204
- * network: false,
205
- * spawn: false,
206
- * allowedPaths: ['/tmp', '/app/data']
207
- * }
208
- */
209
- export interface PermissionSet {
210
- /** Allow file read operations */
211
- fileRead?: boolean;
212
- /** Allow file write operations */
213
- fileWrite?: boolean;
214
- /** Allow network access */
215
- network?: boolean;
216
- /** Allow spawning child processes */
217
- spawn?: boolean;
218
- /** Allow access to environment variables */
219
- env?: boolean;
220
- /** Allow loading native modules */
221
- nativeModules?: boolean;
222
- /** List of allowed file paths (whitelist) */
223
- allowedPaths?: string[];
224
- /** List of allowed environment variable names */
225
- envWhitelist?: string[];
226
- }
227
- /**
228
- * Permission preset types.
229
- *
230
- * @description
231
- * Pre-configured permission sets for common use cases:
232
- * - 'readonly': File read only, no write/network/spawn
233
- * - 'full': All permissions enabled
234
- * - 'network-only': Network access only, no file access
235
- *
236
- * @typedef {'readonly' | 'full' | 'network-only'} PermissionPreset
237
- */
238
- export type PermissionPreset = 'readonly' | 'full' | 'network-only';
239
- /**
240
- * Sandbox configuration.
241
- *
242
- * @description
243
- * Complete configuration options for creating a sandbox instance.
244
- *
245
- * @interface SandboxConfig
246
- *
247
- * @example
248
- * const config: SandboxConfig = {
249
- * timeout: 30000,
250
- * memoryLimit: 256 * 1024 * 1024,
251
- * isolationLevel: 'strict',
252
- * permissionPreset: 'readonly'
253
- * }
254
- */
255
- export interface SandboxConfig {
256
- /** Execution timeout in milliseconds (default: 30000) */
257
- timeout?: number;
258
- /** Memory limit in bytes (default: 256MB) */
259
- memoryLimit?: number;
260
- /** CPU time limit in milliseconds */
261
- cpuTimeLimit?: number;
262
- /** Maximum open file handles */
263
- maxOpenFiles?: number;
264
- /** Maximum spawned processes */
265
- maxProcesses?: number;
266
- /** Network bandwidth limit in bytes/second */
267
- networkBandwidthLimit?: number;
268
- /** Disk write limit in bytes */
269
- diskWriteLimit?: number;
270
- /** Isolation level (default: 'normal') */
271
- isolationLevel?: IsolationLevel;
272
- /** Environment variables to expose */
273
- env?: Record<string, string>;
274
- /** Working directory for file operations */
275
- workingDirectory?: string;
276
- /** Custom permission set */
277
- permissions?: PermissionSet;
278
- /** Use a preset permission configuration */
279
- permissionPreset?: PermissionPreset;
280
- /** Resource limits (alternative to individual limit fields) */
281
- resourceLimits?: ResourceLimits;
282
- /** If true, queue executions when paused instead of rejecting */
283
- queueOnPause?: boolean;
284
- /** Maximum concurrent executions */
285
- maxConcurrentExecutions?: number;
286
- }
287
- /**
288
- * Execution options.
289
- *
290
- * @description
291
- * Options for a single execution within a sandbox.
292
- *
293
- * @interface ExecutionOptions
294
- */
295
- export interface ExecutionOptions {
296
- /** Override default timeout for this execution */
297
- timeout?: number;
298
- /** Additional context data passed to the execution */
299
- context?: Record<string, unknown>;
300
- }
301
- /**
302
- * Resource usage statistics.
303
- *
304
- * @description
305
- * Statistics about resource usage accumulated across sandbox executions.
306
- *
307
- * @interface ResourceStats
308
- */
309
- export interface ResourceStats {
310
- /** Current memory usage in bytes */
311
- memoryUsed: number;
312
- /** Total CPU time used in milliseconds */
313
- cpuTimeUsed: number;
314
- /** Number of executions performed */
315
- executionCount: number;
316
- /** Number of active handles/resources */
317
- activeHandles: number;
318
- }
319
- /**
320
- * Resource usage in result.
321
- *
322
- * @description
323
- * Resource usage information for a specific execution.
324
- *
325
- * @interface ResourceUsage
326
- */
327
- export interface ResourceUsage {
328
- /** Memory used during execution */
329
- memoryUsed: number;
330
- /** CPU time used during execution */
331
- cpuTimeUsed?: number;
332
- }
333
- /**
334
- * Result metadata.
335
- *
336
- * @description
337
- * Timing information for a sandbox execution.
338
- *
339
- * @interface ResultMetadata
340
- */
341
- export interface ResultMetadata {
342
- /** Execution start timestamp (ms since epoch) */
343
- startTime: number;
344
- /** Execution end timestamp (ms since epoch) */
345
- endTime: number;
346
- /** Total elapsed time in milliseconds */
347
- elapsedMs: number;
348
- }
349
- /**
350
- * Permission violation record.
351
- *
352
- * @description
353
- * Records a permission violation attempt for audit purposes.
354
- *
355
- * @interface PermissionViolation
356
- */
357
- export interface PermissionViolation {
358
- /** The permission that was violated */
359
- permission: string;
360
- /** When the violation occurred (ms since epoch) */
361
- timestamp: number;
362
- /** Additional details about the violation */
363
- details?: string;
364
- }
365
- /**
366
- * Sandbox execution result.
367
- *
368
- * @description
369
- * The result of executing code within a sandbox. Contains either
370
- * a value (on success) or an error (on failure), plus metadata.
371
- *
372
- * @interface SandboxResult
373
- * @template T - Type of the return value
374
- *
375
- * @example
376
- * const result = await sandbox.execute<number>(() => 42)
377
- * if (result.error) {
378
- * console.error('Failed:', result.error.message)
379
- * } else {
380
- * console.log('Success:', result.value) // 42
381
- * }
382
- */
383
- export interface SandboxResult<T = unknown> {
384
- /** The execution result value (on success) */
385
- value?: T;
386
- /** The error (on failure) */
387
- error?: SandboxError;
388
- /** ID of the sandbox that executed the code */
389
- sandboxId: string;
390
- /** Timing metadata */
391
- metadata?: ResultMetadata;
392
- /** Resource usage during execution */
393
- resourceUsage?: ResourceUsage;
394
- }
395
- /**
396
- * MCP Sandbox class for isolated execution.
397
- *
398
- * @description
399
- * Provides an isolated execution environment with resource limits and
400
- * permission controls. Uses multi-layer security including static analysis,
401
- * runtime permission checks, and resource limit enforcement.
402
- *
403
- * SECURITY: This implementation uses Node.js vm module concepts with proper
404
- * context isolation and runtime permission checks instead of string analysis.
405
- *
406
- * Lifecycle:
407
- * 1. Create sandbox with createSandbox() or new MCPSandbox()
408
- * 2. Start the sandbox with start()
409
- * 3. Execute code with execute()
410
- * 4. Optionally pause()/resume()
411
- * 5. Cleanup with cleanup() or destroy()
412
- *
413
- * @class MCPSandbox
414
- * @extends EventEmitter
415
- *
416
- * @fires stateChange - When sandbox state changes
417
- *
418
- * @example
419
- * const sandbox = new MCPSandbox({
420
- * timeout: 5000,
421
- * permissions: { fileRead: true, fileWrite: false }
422
- * })
423
- *
424
- * await sandbox.start()
425
- *
426
- * const result = await sandbox.execute(() => {
427
- * return 'Hello from sandbox!'
428
- * })
429
- *
430
- * console.log(result.value) // 'Hello from sandbox!'
431
- *
432
- * await sandbox.destroy()
433
- */
434
- export declare class MCPSandbox extends EventEmitter {
435
- private id;
436
- private config;
437
- private state;
438
- private resourceStats;
439
- private permissionViolations;
440
- private permissions;
441
- private executionQueue;
442
- private activeExecutions;
443
- private globalContext;
444
- /**
445
- * Create a new sandbox instance.
446
- * @param config - Configuration options
447
- */
448
- constructor(config?: SandboxConfig);
449
- /**
450
- * Get the sandbox ID.
451
- * @returns Unique sandbox identifier
452
- */
453
- getId(): string;
454
- /**
455
- * Get the sandbox configuration.
456
- * @returns Copy of the configuration
457
- */
458
- getConfig(): SandboxConfig;
459
- /**
460
- * Get the current sandbox state.
461
- * @returns Current SandboxState
462
- */
463
- getState(): SandboxState;
464
- /**
465
- * Get the current permission set.
466
- * @returns Copy of permissions
467
- */
468
- getPermissions(): PermissionSet;
469
- /**
470
- * Get resource usage statistics.
471
- * @returns Copy of resource stats
472
- */
473
- getResourceStats(): ResourceStats;
474
- /**
475
- * Get configured resource limits.
476
- * @returns Copy of resource limits
477
- */
478
- getResourceLimits(): ResourceLimits;
479
- /**
480
- * Get list of permission violations.
481
- * @returns Array of recorded violations
482
- */
483
- getPermissionViolations(): PermissionViolation[];
484
- /**
485
- * Start the sandbox.
486
- *
487
- * @description
488
- * Transitions the sandbox to RUNNING state. Must be called before execute().
489
- *
490
- * @returns Promise that resolves when started
491
- * @throws {Error} If sandbox is destroyed or already running
492
- */
493
- start(): Promise<void>;
494
- /**
495
- * Stop the sandbox.
496
- *
497
- * @description
498
- * Transitions from RUNNING or PAUSED to IDLE state. Clears global context.
499
- *
500
- * @returns Promise that resolves when stopped
501
- * @throws {Error} If sandbox is not running
502
- */
503
- stop(): Promise<void>;
504
- /**
505
- * Pause the sandbox.
506
- *
507
- * @description
508
- * Temporarily pauses execution. New execute() calls will be queued if
509
- * queueOnPause is enabled, otherwise they return immediately with an error.
510
- *
511
- * @returns Promise that resolves when paused
512
- * @throws {Error} If sandbox is not running
513
- */
514
- pause(): Promise<void>;
515
- /**
516
- * Resume the sandbox.
517
- *
518
- * @description
519
- * Resumes execution after pause. Processes any queued executions.
520
- *
521
- * @returns Promise that resolves when resumed
522
- * @throws {Error} If sandbox is not paused
523
- */
524
- resume(): Promise<void>;
525
- /**
526
- * Cleanup sandbox resources.
527
- *
528
- * @description
529
- * Resets resource statistics and clears global context. Sandbox remains
530
- * usable after cleanup.
531
- *
532
- * @returns Promise that resolves when cleanup is complete
533
- */
534
- cleanup(): Promise<void>;
535
- /**
536
- * Destroy the sandbox.
537
- *
538
- * @description
539
- * Permanently destroys the sandbox. It cannot be reused after destruction.
540
- *
541
- * @returns Promise that resolves when destroyed
542
- */
543
- destroy(): Promise<void>;
544
- /**
545
- * Execute a function in the sandbox.
546
- *
547
- * @description
548
- * Executes the provided function within the sandbox's isolated environment.
549
- * The function is subject to configured timeout, resource limits, and
550
- * permission restrictions.
551
- *
552
- * @template T - Return type of the function
553
- * @param fn - Function to execute (sync or async)
554
- * @param options - Execution options (timeout, context)
555
- * @returns Promise resolving to SandboxResult with value or error
556
- *
557
- * @example
558
- * const result = await sandbox.execute<number>(() => {
559
- * return 42
560
- * })
561
- *
562
- * if (result.error) {
563
- * console.error('Failed:', result.error.code)
564
- * } else {
565
- * console.log('Result:', result.value) // 42
566
- * }
567
- */
568
- execute<T>(fn: (() => T) | (() => Promise<T>), options?: ExecutionOptions): Promise<SandboxResult<T>>;
569
- private executeInSandbox;
570
- /**
571
- * Pre-check function for static analysis of potential violations
572
- *
573
- * SECURITY NOTE: This performs two types of checks:
574
- * 1. Resource limit checks (memory, CPU, bandwidth) - defense-in-depth for obvious cases
575
- * 2. Permission checks for module imports - enforced before execution starts
576
- *
577
- * The permission checks here are CRITICAL for security because we cannot intercept
578
- * dynamic import() calls at runtime without experimental Node.js loader hooks.
579
- * By analyzing the function source, we can detect which modules will be imported
580
- * and block execution before it starts.
581
- *
582
- * This is combined with runtime fs proxy checks for additional security layers.
583
- */
584
- private preCheckResourceLimits;
585
- /**
586
- * Create a secure require/import function that enforces runtime permission checks
587
- */
588
- private createSecureImport;
589
- /**
590
- * Create a secure fs module proxy that checks permissions at runtime
591
- */
592
- private createSecureFs;
593
- /**
594
- * Run function with secure context using runtime permission checks
595
- *
596
- * SECURITY: This replaces the previous string-analysis approach with
597
- * actual runtime interception of dangerous operations.
598
- */
599
- private runWithSecureContext;
600
- /**
601
- * Wrap the user function to intercept dynamic imports
602
- */
603
- private wrapFunctionWithSecureImports;
604
- /**
605
- * Create an isolated process object with permission checks
606
- */
607
- private createIsolatedProcess;
608
- private createIsolatedEnv;
609
- private createPermissionError;
610
- private recordPermissionViolation;
611
- private wrapError;
612
- }
613
- /**
614
- * Create a new sandbox instance.
615
- *
616
- * @description
617
- * Factory function for creating a new MCPSandbox instance.
618
- * Equivalent to using `new MCPSandbox(config)`.
619
- *
620
- * @param config - Sandbox configuration options
621
- * @returns A new MCPSandbox instance
622
- *
623
- * @example
624
- * import { createSandbox } from './sandbox'
625
- *
626
- * const sandbox = createSandbox({
627
- * timeout: 5000,
628
- * permissions: { fileRead: true, network: false }
629
- * })
630
- *
631
- * await sandbox.start()
632
- * const result = await sandbox.execute(() => 'Hello!')
633
- */
634
- export declare function createSandbox(config?: SandboxConfig): MCPSandbox;
635
- /**
636
- * Sandbox pool configuration.
637
- *
638
- * @description
639
- * Configuration for creating a pool of sandbox instances.
640
- *
641
- * @interface SandboxPoolConfig
642
- */
643
- export interface SandboxPoolConfig {
644
- /** Number of sandboxes in the pool */
645
- size: number;
646
- /** Timeout for acquiring a sandbox (ms, default: 30000) */
647
- acquireTimeout?: number;
648
- /** Configuration applied to all sandboxes in the pool */
649
- sandboxConfig?: SandboxConfig;
650
- }
651
- /**
652
- * Sandbox pool for managing multiple sandbox instances.
653
- *
654
- * @description
655
- * Manages a fixed-size pool of sandbox instances for concurrent execution.
656
- * Provides acquire/release semantics with automatic waiting and timeout.
657
- *
658
- * @class SandboxPool
659
- *
660
- * @example
661
- * const pool = new SandboxPool({
662
- * size: 4,
663
- * acquireTimeout: 10000,
664
- * sandboxConfig: { timeout: 5000 }
665
- * })
666
- *
667
- * // Acquire a sandbox
668
- * const sandbox = await pool.acquire()
669
- *
670
- * try {
671
- * const result = await sandbox.execute(() => 'Hello')
672
- * } finally {
673
- * await pool.release(sandbox)
674
- * }
675
- *
676
- * // Shutdown when done
677
- * await pool.shutdown()
678
- */
679
- export declare class SandboxPool {
680
- /** @internal */
681
- private sandboxes;
682
- /** @internal */
683
- private availableSandboxes;
684
- /** @internal */
685
- private acquireTimeout;
686
- /** @internal */
687
- private waiters;
688
- /** @internal */
689
- private isShutdown;
690
- /**
691
- * Create a new sandbox pool.
692
- * @param config - Pool configuration
693
- */
694
- constructor(config: SandboxPoolConfig);
695
- /**
696
- * Get total number of sandboxes in the pool.
697
- * @returns Pool size
698
- */
699
- size(): number;
700
- /**
701
- * Get number of available (not in use) sandboxes.
702
- * @returns Number of available sandboxes
703
- */
704
- available(): number;
705
- /**
706
- * Acquire a sandbox from the pool.
707
- *
708
- * @description
709
- * Returns an available sandbox or waits until one becomes available.
710
- * The sandbox is started if in IDLE state.
711
- *
712
- * @returns Promise resolving to an acquired sandbox
713
- * @throws {Error} If pool is shutdown or acquire times out
714
- */
715
- acquire(): Promise<MCPSandbox>;
716
- /**
717
- * Release a sandbox back to the pool.
718
- *
719
- * @description
720
- * Returns a sandbox to the pool after use. The sandbox is cleaned up
721
- * before being made available again. If waiters are present, the sandbox
722
- * is given to the next waiter instead of being added to the available pool.
723
- *
724
- * @param sandbox - The sandbox to release
725
- * @returns Promise that resolves when the sandbox is released
726
- */
727
- release(sandbox: MCPSandbox): Promise<void>;
728
- /**
729
- * Shutdown the pool.
730
- *
731
- * @description
732
- * Rejects all pending waiters, destroys all sandboxes, and prevents
733
- * further acquire operations. This is a permanent operation.
734
- *
735
- * @returns Promise that resolves when shutdown is complete
736
- */
737
- shutdown(): Promise<void>;
738
- }
739
- /**
740
- * Create a sandbox pool.
741
- *
742
- * @description
743
- * Factory function for creating a new SandboxPool instance.
744
- * Equivalent to using `new SandboxPool(config)`.
745
- *
746
- * @param config - Pool configuration
747
- * @returns A new SandboxPool instance
748
- *
749
- * @example
750
- * import { createSandboxPool } from './sandbox'
751
- *
752
- * const pool = createSandboxPool({
753
- * size: 4,
754
- * sandboxConfig: { timeout: 10000 }
755
- * })
756
- *
757
- * const sandbox = await pool.acquire()
758
- * // ... use sandbox ...
759
- * await pool.release(sandbox)
760
- *
761
- * await pool.shutdown()
762
- */
763
- export declare function createSandboxPool(config: SandboxPoolConfig): SandboxPool;
764
- //# sourceMappingURL=sandbox.d.ts.map