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.
- package/README.md +40 -353
- package/dist/do/logger.d.ts +50 -0
- package/dist/do/logger.d.ts.map +1 -0
- package/dist/do/logger.js +122 -0
- package/dist/do/logger.js.map +1 -0
- package/dist/{durable-object → do}/schema.d.ts +3 -3
- package/dist/do/schema.d.ts.map +1 -0
- package/dist/{durable-object → do}/schema.js +4 -3
- package/dist/do/schema.js.map +1 -0
- package/dist/do/types.d.ts +267 -0
- package/dist/do/types.d.ts.map +1 -0
- package/dist/do/types.js +62 -0
- package/dist/do/types.js.map +1 -0
- package/dist/index.d.ts +15 -469
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -481
- package/dist/index.js.map +1 -1
- package/dist/mcp/auth.d.ts +77 -0
- package/dist/mcp/auth.d.ts.map +1 -0
- package/dist/mcp/auth.js +278 -0
- package/dist/mcp/auth.js.map +1 -0
- package/dist/mcp/index.d.ts +13 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +19 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/server.d.ts +200 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +275 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tool-registry.d.ts +47 -0
- package/dist/mcp/tool-registry.d.ts.map +1 -0
- package/dist/mcp/tool-registry.js +284 -0
- package/dist/mcp/tool-registry.js.map +1 -0
- package/dist/mcp/tools.d.ts +103 -515
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +676 -3087
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/types.d.ts +124 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +9 -0
- package/dist/mcp/types.js.map +1 -0
- package/package.json +19 -21
- package/dist/cli/commands/add.d.ts +0 -176
- package/dist/cli/commands/add.d.ts.map +0 -1
- package/dist/cli/commands/add.js +0 -979
- package/dist/cli/commands/add.js.map +0 -1
- package/dist/cli/commands/blame.d.ts +0 -259
- package/dist/cli/commands/blame.d.ts.map +0 -1
- package/dist/cli/commands/blame.js +0 -609
- package/dist/cli/commands/blame.js.map +0 -1
- package/dist/cli/commands/branch.d.ts +0 -249
- package/dist/cli/commands/branch.d.ts.map +0 -1
- package/dist/cli/commands/branch.js +0 -693
- package/dist/cli/commands/branch.js.map +0 -1
- package/dist/cli/commands/checkout.d.ts +0 -73
- package/dist/cli/commands/checkout.d.ts.map +0 -1
- package/dist/cli/commands/checkout.js +0 -725
- package/dist/cli/commands/checkout.js.map +0 -1
- package/dist/cli/commands/commit.d.ts +0 -182
- package/dist/cli/commands/commit.d.ts.map +0 -1
- package/dist/cli/commands/commit.js +0 -457
- package/dist/cli/commands/commit.js.map +0 -1
- package/dist/cli/commands/diff.d.ts +0 -464
- package/dist/cli/commands/diff.d.ts.map +0 -1
- package/dist/cli/commands/diff.js +0 -959
- package/dist/cli/commands/diff.js.map +0 -1
- package/dist/cli/commands/log.d.ts +0 -239
- package/dist/cli/commands/log.d.ts.map +0 -1
- package/dist/cli/commands/log.js +0 -535
- package/dist/cli/commands/log.js.map +0 -1
- package/dist/cli/commands/merge.d.ts +0 -106
- package/dist/cli/commands/merge.d.ts.map +0 -1
- package/dist/cli/commands/merge.js +0 -852
- package/dist/cli/commands/merge.js.map +0 -1
- package/dist/cli/commands/review.d.ts +0 -457
- package/dist/cli/commands/review.d.ts.map +0 -1
- package/dist/cli/commands/review.js +0 -558
- package/dist/cli/commands/review.js.map +0 -1
- package/dist/cli/commands/stash.d.ts +0 -157
- package/dist/cli/commands/stash.d.ts.map +0 -1
- package/dist/cli/commands/stash.js +0 -655
- package/dist/cli/commands/stash.js.map +0 -1
- package/dist/cli/commands/status.d.ts +0 -269
- package/dist/cli/commands/status.d.ts.map +0 -1
- package/dist/cli/commands/status.js +0 -492
- package/dist/cli/commands/status.js.map +0 -1
- package/dist/cli/commands/web.d.ts +0 -199
- package/dist/cli/commands/web.d.ts.map +0 -1
- package/dist/cli/commands/web.js +0 -697
- package/dist/cli/commands/web.js.map +0 -1
- package/dist/cli/fs-adapter.d.ts +0 -656
- package/dist/cli/fs-adapter.d.ts.map +0 -1
- package/dist/cli/fs-adapter.js +0 -1177
- package/dist/cli/fs-adapter.js.map +0 -1
- package/dist/cli/fsx-cli-adapter.d.ts +0 -359
- package/dist/cli/fsx-cli-adapter.d.ts.map +0 -1
- package/dist/cli/fsx-cli-adapter.js +0 -619
- package/dist/cli/fsx-cli-adapter.js.map +0 -1
- package/dist/cli/index.d.ts +0 -387
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js +0 -579
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/ui/components/DiffView.d.ts +0 -12
- package/dist/cli/ui/components/DiffView.d.ts.map +0 -1
- package/dist/cli/ui/components/DiffView.js +0 -11
- package/dist/cli/ui/components/DiffView.js.map +0 -1
- package/dist/cli/ui/components/ErrorDisplay.d.ts +0 -10
- package/dist/cli/ui/components/ErrorDisplay.d.ts.map +0 -1
- package/dist/cli/ui/components/ErrorDisplay.js +0 -11
- package/dist/cli/ui/components/ErrorDisplay.js.map +0 -1
- package/dist/cli/ui/components/FuzzySearch.d.ts +0 -15
- package/dist/cli/ui/components/FuzzySearch.d.ts.map +0 -1
- package/dist/cli/ui/components/FuzzySearch.js +0 -12
- package/dist/cli/ui/components/FuzzySearch.js.map +0 -1
- package/dist/cli/ui/components/LoadingSpinner.d.ts +0 -10
- package/dist/cli/ui/components/LoadingSpinner.d.ts.map +0 -1
- package/dist/cli/ui/components/LoadingSpinner.js +0 -10
- package/dist/cli/ui/components/LoadingSpinner.js.map +0 -1
- package/dist/cli/ui/components/NavigationList.d.ts +0 -14
- package/dist/cli/ui/components/NavigationList.d.ts.map +0 -1
- package/dist/cli/ui/components/NavigationList.js +0 -11
- package/dist/cli/ui/components/NavigationList.js.map +0 -1
- package/dist/cli/ui/components/ScrollableContent.d.ts +0 -13
- package/dist/cli/ui/components/ScrollableContent.d.ts.map +0 -1
- package/dist/cli/ui/components/ScrollableContent.js +0 -11
- package/dist/cli/ui/components/ScrollableContent.js.map +0 -1
- package/dist/cli/ui/components/index.d.ts +0 -7
- package/dist/cli/ui/components/index.d.ts.map +0 -1
- package/dist/cli/ui/components/index.js +0 -9
- package/dist/cli/ui/components/index.js.map +0 -1
- package/dist/cli/ui/terminal-ui.d.ts +0 -85
- package/dist/cli/ui/terminal-ui.d.ts.map +0 -1
- package/dist/cli/ui/terminal-ui.js +0 -121
- package/dist/cli/ui/terminal-ui.js.map +0 -1
- package/dist/do/BashModule.d.ts +0 -871
- package/dist/do/BashModule.d.ts.map +0 -1
- package/dist/do/BashModule.js +0 -1143
- package/dist/do/BashModule.js.map +0 -1
- package/dist/do/FsModule.d.ts +0 -612
- package/dist/do/FsModule.d.ts.map +0 -1
- package/dist/do/FsModule.js +0 -1120
- package/dist/do/FsModule.js.map +0 -1
- package/dist/do/GitModule.d.ts +0 -635
- package/dist/do/GitModule.d.ts.map +0 -1
- package/dist/do/GitModule.js +0 -784
- package/dist/do/GitModule.js.map +0 -1
- package/dist/do/GitRepoDO.d.ts +0 -281
- package/dist/do/GitRepoDO.d.ts.map +0 -1
- package/dist/do/GitRepoDO.js +0 -479
- package/dist/do/GitRepoDO.js.map +0 -1
- package/dist/do/bash-ast.d.ts +0 -246
- package/dist/do/bash-ast.d.ts.map +0 -1
- package/dist/do/bash-ast.js +0 -888
- package/dist/do/bash-ast.js.map +0 -1
- package/dist/do/container-executor.d.ts +0 -491
- package/dist/do/container-executor.d.ts.map +0 -1
- package/dist/do/container-executor.js +0 -731
- package/dist/do/container-executor.js.map +0 -1
- package/dist/do/index.d.ts +0 -53
- package/dist/do/index.d.ts.map +0 -1
- package/dist/do/index.js +0 -91
- package/dist/do/index.js.map +0 -1
- package/dist/do/tiered-storage.d.ts +0 -403
- package/dist/do/tiered-storage.d.ts.map +0 -1
- package/dist/do/tiered-storage.js +0 -689
- package/dist/do/tiered-storage.js.map +0 -1
- package/dist/do/withBash.d.ts +0 -231
- package/dist/do/withBash.d.ts.map +0 -1
- package/dist/do/withBash.js +0 -244
- package/dist/do/withBash.js.map +0 -1
- package/dist/do/withFs.d.ts +0 -237
- package/dist/do/withFs.d.ts.map +0 -1
- package/dist/do/withFs.js +0 -387
- package/dist/do/withFs.js.map +0 -1
- package/dist/do/withGit.d.ts +0 -180
- package/dist/do/withGit.d.ts.map +0 -1
- package/dist/do/withGit.js +0 -271
- package/dist/do/withGit.js.map +0 -1
- package/dist/durable-object/object-store.d.ts +0 -633
- package/dist/durable-object/object-store.d.ts.map +0 -1
- package/dist/durable-object/object-store.js +0 -1164
- package/dist/durable-object/object-store.js.map +0 -1
- package/dist/durable-object/schema.d.ts.map +0 -1
- package/dist/durable-object/schema.js.map +0 -1
- package/dist/durable-object/wal.d.ts +0 -416
- package/dist/durable-object/wal.d.ts.map +0 -1
- package/dist/durable-object/wal.js +0 -445
- package/dist/durable-object/wal.js.map +0 -1
- package/dist/mcp/adapter.d.ts +0 -772
- package/dist/mcp/adapter.d.ts.map +0 -1
- package/dist/mcp/adapter.js +0 -895
- package/dist/mcp/adapter.js.map +0 -1
- package/dist/mcp/sandbox/miniflare-evaluator.d.ts +0 -22
- package/dist/mcp/sandbox/miniflare-evaluator.d.ts.map +0 -1
- package/dist/mcp/sandbox/miniflare-evaluator.js +0 -140
- package/dist/mcp/sandbox/miniflare-evaluator.js.map +0 -1
- package/dist/mcp/sandbox/object-store-proxy.d.ts +0 -32
- package/dist/mcp/sandbox/object-store-proxy.d.ts.map +0 -1
- package/dist/mcp/sandbox/object-store-proxy.js +0 -30
- package/dist/mcp/sandbox/object-store-proxy.js.map +0 -1
- package/dist/mcp/sandbox/template.d.ts +0 -17
- package/dist/mcp/sandbox/template.d.ts.map +0 -1
- package/dist/mcp/sandbox/template.js +0 -71
- package/dist/mcp/sandbox/template.js.map +0 -1
- package/dist/mcp/sandbox.d.ts +0 -764
- package/dist/mcp/sandbox.d.ts.map +0 -1
- package/dist/mcp/sandbox.js +0 -1362
- package/dist/mcp/sandbox.js.map +0 -1
- package/dist/mcp/sdk-adapter.d.ts +0 -835
- package/dist/mcp/sdk-adapter.d.ts.map +0 -1
- package/dist/mcp/sdk-adapter.js +0 -974
- package/dist/mcp/sdk-adapter.js.map +0 -1
- package/dist/mcp/tools/do.d.ts +0 -32
- package/dist/mcp/tools/do.d.ts.map +0 -1
- package/dist/mcp/tools/do.js +0 -117
- package/dist/mcp/tools/do.js.map +0 -1
- package/dist/ops/blame.d.ts +0 -551
- package/dist/ops/blame.d.ts.map +0 -1
- package/dist/ops/blame.js +0 -1037
- package/dist/ops/blame.js.map +0 -1
- package/dist/ops/branch.d.ts +0 -766
- package/dist/ops/branch.d.ts.map +0 -1
- package/dist/ops/branch.js +0 -950
- package/dist/ops/branch.js.map +0 -1
- package/dist/ops/commit-traversal.d.ts +0 -349
- package/dist/ops/commit-traversal.d.ts.map +0 -1
- package/dist/ops/commit-traversal.js +0 -821
- package/dist/ops/commit-traversal.js.map +0 -1
- package/dist/ops/commit.d.ts +0 -555
- package/dist/ops/commit.d.ts.map +0 -1
- package/dist/ops/commit.js +0 -826
- package/dist/ops/commit.js.map +0 -1
- package/dist/ops/merge-base.d.ts +0 -397
- package/dist/ops/merge-base.d.ts.map +0 -1
- package/dist/ops/merge-base.js +0 -691
- package/dist/ops/merge-base.js.map +0 -1
- package/dist/ops/merge.d.ts +0 -855
- package/dist/ops/merge.d.ts.map +0 -1
- package/dist/ops/merge.js +0 -1551
- package/dist/ops/merge.js.map +0 -1
- package/dist/ops/tag.d.ts +0 -247
- package/dist/ops/tag.d.ts.map +0 -1
- package/dist/ops/tag.js +0 -649
- package/dist/ops/tag.js.map +0 -1
- package/dist/ops/tree-builder.d.ts +0 -178
- package/dist/ops/tree-builder.d.ts.map +0 -1
- package/dist/ops/tree-builder.js +0 -271
- package/dist/ops/tree-builder.js.map +0 -1
- package/dist/ops/tree-diff.d.ts +0 -291
- package/dist/ops/tree-diff.d.ts.map +0 -1
- package/dist/ops/tree-diff.js +0 -705
- package/dist/ops/tree-diff.js.map +0 -1
- package/dist/pack/delta.d.ts +0 -248
- package/dist/pack/delta.d.ts.map +0 -1
- package/dist/pack/delta.js +0 -740
- package/dist/pack/delta.js.map +0 -1
- package/dist/pack/format.d.ts +0 -446
- package/dist/pack/format.d.ts.map +0 -1
- package/dist/pack/format.js +0 -572
- package/dist/pack/format.js.map +0 -1
- package/dist/pack/full-generation.d.ts +0 -612
- package/dist/pack/full-generation.d.ts.map +0 -1
- package/dist/pack/full-generation.js +0 -1378
- package/dist/pack/full-generation.js.map +0 -1
- package/dist/pack/generation.d.ts +0 -441
- package/dist/pack/generation.d.ts.map +0 -1
- package/dist/pack/generation.js +0 -707
- package/dist/pack/generation.js.map +0 -1
- package/dist/pack/index.d.ts +0 -502
- package/dist/pack/index.d.ts.map +0 -1
- package/dist/pack/index.js +0 -833
- package/dist/pack/index.js.map +0 -1
- package/dist/refs/branch.d.ts +0 -683
- package/dist/refs/branch.d.ts.map +0 -1
- package/dist/refs/branch.js +0 -881
- package/dist/refs/branch.js.map +0 -1
- package/dist/refs/storage.d.ts +0 -833
- package/dist/refs/storage.d.ts.map +0 -1
- package/dist/refs/storage.js +0 -1023
- package/dist/refs/storage.js.map +0 -1
- package/dist/refs/tag.d.ts +0 -860
- package/dist/refs/tag.d.ts.map +0 -1
- package/dist/refs/tag.js +0 -996
- package/dist/refs/tag.js.map +0 -1
- package/dist/storage/backend.d.ts +0 -425
- package/dist/storage/backend.d.ts.map +0 -1
- package/dist/storage/backend.js +0 -41
- package/dist/storage/backend.js.map +0 -1
- package/dist/storage/fsx-adapter.d.ts +0 -204
- package/dist/storage/fsx-adapter.d.ts.map +0 -1
- package/dist/storage/fsx-adapter.js +0 -518
- package/dist/storage/fsx-adapter.js.map +0 -1
- package/dist/storage/lru-cache.d.ts +0 -691
- package/dist/storage/lru-cache.d.ts.map +0 -1
- package/dist/storage/lru-cache.js +0 -813
- package/dist/storage/lru-cache.js.map +0 -1
- package/dist/storage/object-index.d.ts +0 -585
- package/dist/storage/object-index.d.ts.map +0 -1
- package/dist/storage/object-index.js +0 -532
- package/dist/storage/object-index.js.map +0 -1
- package/dist/storage/r2-pack.d.ts +0 -1257
- package/dist/storage/r2-pack.d.ts.map +0 -1
- package/dist/storage/r2-pack.js +0 -1773
- package/dist/storage/r2-pack.js.map +0 -1
- package/dist/tiered/cdc-pipeline.d.ts +0 -1888
- package/dist/tiered/cdc-pipeline.d.ts.map +0 -1
- package/dist/tiered/cdc-pipeline.js +0 -1880
- package/dist/tiered/cdc-pipeline.js.map +0 -1
- package/dist/tiered/migration.d.ts +0 -1104
- package/dist/tiered/migration.d.ts.map +0 -1
- package/dist/tiered/migration.js +0 -1217
- package/dist/tiered/migration.js.map +0 -1
- package/dist/tiered/parquet-writer.d.ts +0 -1145
- package/dist/tiered/parquet-writer.d.ts.map +0 -1
- package/dist/tiered/parquet-writer.js +0 -1183
- package/dist/tiered/parquet-writer.js.map +0 -1
- package/dist/tiered/read-path.d.ts +0 -835
- package/dist/tiered/read-path.d.ts.map +0 -1
- package/dist/tiered/read-path.js +0 -487
- package/dist/tiered/read-path.js.map +0 -1
- package/dist/types/capability.d.ts +0 -1385
- package/dist/types/capability.d.ts.map +0 -1
- package/dist/types/capability.js +0 -36
- package/dist/types/capability.js.map +0 -1
- package/dist/types/index.d.ts +0 -13
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -18
- package/dist/types/index.js.map +0 -1
- package/dist/types/interfaces.d.ts +0 -673
- package/dist/types/interfaces.d.ts.map +0 -1
- package/dist/types/interfaces.js +0 -26
- package/dist/types/interfaces.js.map +0 -1
- package/dist/types/objects.d.ts +0 -692
- package/dist/types/objects.d.ts.map +0 -1
- package/dist/types/objects.js +0 -837
- package/dist/types/objects.js.map +0 -1
- package/dist/types/storage.d.ts +0 -603
- package/dist/types/storage.d.ts.map +0 -1
- package/dist/types/storage.js +0 -191
- package/dist/types/storage.js.map +0 -1
- package/dist/types/worker-loader.d.ts +0 -60
- package/dist/types/worker-loader.d.ts.map +0 -1
- package/dist/types/worker-loader.js +0 -62
- package/dist/types/worker-loader.js.map +0 -1
- package/dist/utils/hash.d.ts +0 -198
- package/dist/utils/hash.d.ts.map +0 -1
- package/dist/utils/hash.js +0 -272
- package/dist/utils/hash.js.map +0 -1
- package/dist/utils/sha1.d.ts +0 -325
- package/dist/utils/sha1.d.ts.map +0 -1
- package/dist/utils/sha1.js +0 -635
- package/dist/utils/sha1.js.map +0 -1
- package/dist/wire/capabilities.d.ts +0 -1044
- package/dist/wire/capabilities.d.ts.map +0 -1
- package/dist/wire/capabilities.js +0 -941
- package/dist/wire/capabilities.js.map +0 -1
- package/dist/wire/path-security.d.ts +0 -157
- package/dist/wire/path-security.d.ts.map +0 -1
- package/dist/wire/path-security.js +0 -307
- package/dist/wire/path-security.js.map +0 -1
- package/dist/wire/pkt-line.d.ts +0 -345
- package/dist/wire/pkt-line.d.ts.map +0 -1
- package/dist/wire/pkt-line.js +0 -381
- package/dist/wire/pkt-line.js.map +0 -1
- package/dist/wire/receive-pack.d.ts +0 -1059
- package/dist/wire/receive-pack.d.ts.map +0 -1
- package/dist/wire/receive-pack.js +0 -1414
- package/dist/wire/receive-pack.js.map +0 -1
- package/dist/wire/smart-http.d.ts +0 -799
- package/dist/wire/smart-http.d.ts.map +0 -1
- package/dist/wire/smart-http.js +0 -945
- package/dist/wire/smart-http.js.map +0 -1
- package/dist/wire/upload-pack.d.ts +0 -727
- package/dist/wire/upload-pack.d.ts.map +0 -1
- package/dist/wire/upload-pack.js +0 -1141
- package/dist/wire/upload-pack.js.map +0 -1
package/dist/mcp/sandbox.d.ts
DELETED
|
@@ -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
|