@mastra/docker 0.0.0-a2a-vnext-20260424123427

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Docker Sandbox Provider Descriptor
3
+ *
4
+ * Enables registration with MastraEditor for UI-driven sandbox configuration.
5
+ */
6
+ import type { SandboxProvider } from '@mastra/core/editor';
7
+ /**
8
+ * Serializable config for the Docker sandbox provider.
9
+ * This is the subset of DockerSandboxOptions that can be stored in a config file
10
+ * and rendered in a UI form.
11
+ */
12
+ export interface DockerProviderConfig {
13
+ /** Docker image to use */
14
+ image?: string;
15
+ /** Default command timeout in milliseconds */
16
+ timeout?: number;
17
+ /** Environment variables */
18
+ env?: Record<string, string>;
19
+ /** Host-to-container bind mounts */
20
+ volumes?: Record<string, string>;
21
+ /** Docker network to join */
22
+ network?: string;
23
+ /** Working directory inside the container */
24
+ workingDir?: string;
25
+ /** Run in privileged mode */
26
+ privileged?: boolean;
27
+ }
28
+ export declare const dockerSandboxProvider: SandboxProvider<DockerProviderConfig>;
29
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAI3D;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,0BAA0B;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4BAA4B;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,oCAAoC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,6BAA6B;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,eAAO,MAAM,qBAAqB,EAAE,eAAe,CAAC,oBAAoB,CA4CvE,CAAC"}
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Docker Sandbox Provider
3
+ *
4
+ * A Docker-based sandbox implementation that uses long-lived containers
5
+ * with `docker exec` for command execution. Targets local development,
6
+ * CI/CD, air-gapped deployments, and cost-sensitive scenarios where
7
+ * cloud sandboxes are overkill.
8
+ *
9
+ * @see https://docs.docker.com/engine/api/
10
+ */
11
+ import type { RequestContext } from '@mastra/core/di';
12
+ import type { SandboxInfo, ProviderStatus, MastraSandboxOptions } from '@mastra/core/workspace';
13
+ import { MastraSandbox } from '@mastra/core/workspace';
14
+ import Docker from 'dockerode';
15
+ import type { Container } from 'dockerode';
16
+ import { DockerProcessManager } from './process-manager.js';
17
+ /**
18
+ * Inlined from `@mastra/core/workspace` to avoid requiring a newer core peer dep.
19
+ * Canonical type: packages/core/src/workspace/sandbox/mastra-sandbox.ts
20
+ * TODO: Remove once minimum peer dep includes InstructionsOption export.
21
+ */
22
+ type InstructionsOption = string | ((opts: {
23
+ defaultInstructions: string;
24
+ requestContext?: RequestContext;
25
+ }) => string);
26
+ export interface DockerSandboxOptions extends Omit<MastraSandboxOptions, 'processes'> {
27
+ /** Unique identifier for this sandbox instance. Used for container naming and reconnection. */
28
+ id?: string;
29
+ /** Docker image to use.
30
+ * @default 'node:22-slim'
31
+ */
32
+ image?: string;
33
+ /** Container entrypoint command. Must keep the container alive.
34
+ * @default ['sleep', 'infinity']
35
+ */
36
+ command?: string[];
37
+ /** Environment variables to set in the container */
38
+ env?: Record<string, string>;
39
+ /** Host-to-container bind mounts (e.g., `{ '/host/path': '/container/path' }`) */
40
+ volumes?: Record<string, string>;
41
+ /** Docker network to join */
42
+ network?: string;
43
+ /** Run in privileged mode
44
+ * @default false
45
+ */
46
+ privileged?: boolean;
47
+ /** Default command timeout in milliseconds
48
+ * @default 300_000 // 5 minutes
49
+ */
50
+ timeout?: number;
51
+ /** Working directory inside the container
52
+ * @default '/workspace'
53
+ */
54
+ workingDir?: string;
55
+ /** Container labels for filtering and identification */
56
+ labels?: Record<string, string>;
57
+ /** Pass-through dockerode connection options (socket path, host, TLS certs) */
58
+ dockerOptions?: Docker.DockerOptions;
59
+ /**
60
+ * Custom instructions that override the default instructions
61
+ * returned by `getInstructions()`.
62
+ *
63
+ * - `string` — Fully replaces the default instructions.
64
+ * Pass an empty string to suppress instructions entirely.
65
+ * - `(opts) => string` — Receives the default instructions and
66
+ * optional request context so you can extend or customise per-request.
67
+ */
68
+ instructions?: InstructionsOption;
69
+ }
70
+ /**
71
+ * Docker sandbox implementation using long-lived containers.
72
+ *
73
+ * Features:
74
+ * - Long-lived container with `docker exec` for commands
75
+ * - Bind mount support via Docker volumes
76
+ * - Reconnection to existing containers by ID/name
77
+ * - Container label tracking for discovery
78
+ *
79
+ * @example Basic usage
80
+ * ```typescript
81
+ * import { Workspace } from '@mastra/core/workspace';
82
+ * import { DockerSandbox } from '@mastra/docker';
83
+ *
84
+ * const sandbox = new DockerSandbox({
85
+ * image: 'node:22-slim',
86
+ * timeout: 60000,
87
+ * });
88
+ *
89
+ * const workspace = new Workspace({ sandbox });
90
+ * const result = await workspace.executeCode('console.log("Hello!")');
91
+ * ```
92
+ *
93
+ * @example With bind mounts
94
+ * ```typescript
95
+ * const sandbox = new DockerSandbox({
96
+ * image: 'node:22-slim',
97
+ * volumes: { '/my/project': '/workspace/project' },
98
+ * });
99
+ * ```
100
+ */
101
+ export declare class DockerSandbox extends MastraSandbox {
102
+ readonly id: string;
103
+ readonly name = "DockerSandbox";
104
+ readonly provider = "docker";
105
+ status: ProviderStatus;
106
+ readonly processes: DockerProcessManager;
107
+ /** Underlying Docker client */
108
+ private readonly _docker;
109
+ /** Container reference (set after start) */
110
+ private _container;
111
+ /** Configuration */
112
+ private readonly _image;
113
+ private readonly _command;
114
+ private readonly _env;
115
+ private readonly _volumes;
116
+ private readonly _network?;
117
+ private readonly _privileged;
118
+ private readonly _workingDir;
119
+ private readonly _labels;
120
+ private readonly _instructionsOverride?;
121
+ constructor(options?: DockerSandboxOptions);
122
+ /**
123
+ * Get the underlying Docker container for direct access.
124
+ * @throws {SandboxNotReadyError} If the sandbox has not been started.
125
+ */
126
+ get container(): Container;
127
+ start(): Promise<void>;
128
+ stop(): Promise<void>;
129
+ destroy(): Promise<void>;
130
+ getInstructions(opts?: {
131
+ requestContext?: RequestContext;
132
+ }): string;
133
+ getInfo(): Promise<SandboxInfo>;
134
+ private _generateId;
135
+ /**
136
+ * Resolve the container reference, looking up by label if `_container` is unset.
137
+ * This ensures `stop()` and `destroy()` work even when the instance was created
138
+ * with an existing container's ID but `start()` was never called.
139
+ */
140
+ private _resolveContainer;
141
+ /**
142
+ * Find an existing container matching this sandbox's ID via labels.
143
+ */
144
+ private _findExistingContainer;
145
+ /**
146
+ * Ensure the Docker image is available locally. Pulls if needed.
147
+ */
148
+ private _ensureImage;
149
+ }
150
+ export {};
151
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,aAAa,EAAsC,MAAM,wBAAwB,CAAC;AAC3F,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAIzD;;;;GAIG;AACH,KAAK,kBAAkB,GAAG,MAAM,GAAG,CAAC,CAAC,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,4CAA4C;IAC5C,OAAO,CAAC,UAAU,CAA0B;IAE5C,oBAAoB;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAyB;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAClD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAU;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAqB;gBAEhD,OAAO,GAAE,oBAAyB;IA6B9C;;;OAGG;IACH,IAAI,SAAS,IAAI,SAAS,CAKzB;IAMK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA8DtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBrB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB9B,eAAe,CAAC,IAAI,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,cAAc,CAAA;KAAE,GAAG,MAAM;IAiB7D,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC;IAoCrC,OAAO,CAAC,WAAW;IAInB;;;;OAIG;YACW,iBAAiB;IAQ/B;;OAEG;YACW,sBAAsB;IAkBpC;;OAEG;YACW,YAAY;CA8B3B"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Docker Process Manager
3
+ *
4
+ * Implements SandboxProcessManager for Docker containers.
5
+ * Uses `container.exec()` to run commands inside a long-lived container.
6
+ * Each spawned process gets a dedicated exec instance with separate
7
+ * stdout/stderr streams.
8
+ */
9
+ import { ProcessHandle, SandboxProcessManager } from '@mastra/core/workspace';
10
+ import type { ProcessInfo, SpawnProcessOptions } from '@mastra/core/workspace';
11
+ import type { Container } from 'dockerode';
12
+ /**
13
+ * Docker implementation of SandboxProcessManager.
14
+ * Uses `container.exec()` with stream-based I/O.
15
+ */
16
+ export declare class DockerProcessManager extends SandboxProcessManager {
17
+ private _container;
18
+ private readonly _defaultTimeout;
19
+ constructor(options: {
20
+ env: Record<string, string>;
21
+ defaultTimeout?: number;
22
+ });
23
+ /** @internal Called by DockerSandbox after container is ready */
24
+ setContainer(container: Container): void;
25
+ /** Get the container, throwing if not set */
26
+ private get container();
27
+ spawn(command: string, options?: SpawnProcessOptions): Promise<ProcessHandle>;
28
+ /** Clear all tracked process handles and release the container reference (e.g., after container stop/destroy) */
29
+ reset(): void;
30
+ list(): Promise<ProcessInfo[]>;
31
+ }
32
+ //# sourceMappingURL=process-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-manager.d.ts","sourceRoot":"","sources":["../../src/sandbox/process-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,KAAK,EAAiB,WAAW,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,KAAK,EAAE,SAAS,EAAyB,MAAM,WAAW,CAAC;AA6JlE;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,qBAAqB;IAC7D,OAAO,CAAC,UAAU,CAA0B;IAC5C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAE7B,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE;IAK7E,iEAAiE;IACjE,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAIxC,6CAA6C;IAC7C,OAAO,KAAK,SAAS,GAKpB;IAEK,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,aAAa,CAAC;IAgJvF,iHAAiH;IACjH,KAAK,IAAI,IAAI;IAKP,IAAI,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;CAcrC"}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@mastra/docker",
3
+ "version": "0.0.0-a2a-vnext-20260424123427",
4
+ "description": "Docker container sandbox provider for Mastra workspaces",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "license": "Apache-2.0",
22
+ "dependencies": {
23
+ "dockerode": "^4.0.9"
24
+ },
25
+ "devDependencies": {
26
+ "@types/dockerode": "^4.0.1",
27
+ "@types/node": "22.19.15",
28
+ "@vitest/coverage-v8": "4.1.5",
29
+ "@vitest/ui": "4.1.5",
30
+ "eslint": "^10.2.1",
31
+ "tsup": "^8.5.1",
32
+ "typescript": "^5.9.3",
33
+ "vitest": "4.1.5",
34
+ "@internal/lint": "0.0.0-a2a-vnext-20260424123427",
35
+ "@internal/types-builder": "0.0.0-a2a-vnext-20260424123427",
36
+ "@internal/workspace-test-utils": "0.0.30",
37
+ "@mastra/core": "0.0.0-a2a-vnext-20260424123427"
38
+ },
39
+ "peerDependencies": {
40
+ "@mastra/core": "0.0.0-a2a-vnext-20260424123427"
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "CHANGELOG.md"
45
+ ],
46
+ "homepage": "https://mastra.ai",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/mastra-ai/mastra.git",
50
+ "directory": "workspaces/docker"
51
+ },
52
+ "bugs": {
53
+ "url": "https://github.com/mastra-ai/mastra/issues"
54
+ },
55
+ "engines": {
56
+ "node": ">=22.13.0"
57
+ },
58
+ "scripts": {
59
+ "build": "tsup --silent --config tsup.config.ts",
60
+ "build:lib": "pnpm build",
61
+ "build:watch": "pnpm build --watch",
62
+ "test:unit": "vitest run --exclude '**/*.integration.test.ts'",
63
+ "test:watch": "vitest watch",
64
+ "test": "vitest run ./src/**/*.integration.test.ts",
65
+ "test:cloud": "pnpm test",
66
+ "lint": "eslint ."
67
+ }
68
+ }