@mastra/mcp-docs-server 0.0.0-studio-deploy-20260404182525 → 0.0.0-studio-cli-20260504022012
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/.docs/docs/agents/adding-voice.md +18 -17
- package/.docs/docs/agents/background-tasks.md +242 -0
- package/.docs/docs/agents/channels.md +2 -1
- package/.docs/docs/agents/overview.md +4 -0
- package/.docs/docs/agents/processors.md +177 -5
- package/.docs/docs/agents/structured-output.md +66 -1
- package/.docs/docs/agents/supervisor-agents.md +65 -0
- package/.docs/docs/agents/using-tools.md +73 -0
- package/.docs/docs/browser/agent-browser.md +78 -0
- package/.docs/docs/browser/browser-viewer.md +144 -0
- package/.docs/docs/browser/overview.md +168 -0
- package/.docs/docs/browser/stagehand.md +129 -0
- package/.docs/docs/deployment/cloud-providers.md +5 -1
- package/.docs/docs/deployment/mastra-server.md +4 -4
- package/.docs/docs/deployment/monorepo.md +3 -3
- package/.docs/docs/deployment/overview.md +11 -8
- package/.docs/docs/editor/overview.md +290 -0
- package/.docs/docs/editor/prompts.md +134 -0
- package/.docs/docs/editor/tools.md +152 -0
- package/.docs/docs/evals/custom-scorers.md +63 -3
- package/.docs/docs/evals/datasets/overview.md +1 -1
- package/.docs/docs/index.md +2 -2
- package/.docs/docs/mastra-platform/configuration.md +36 -0
- package/.docs/docs/mastra-platform/overview.md +78 -0
- package/.docs/docs/mcp/overview.md +17 -0
- package/.docs/docs/memory/memory-processors.md +3 -3
- package/.docs/docs/memory/message-history.md +8 -2
- package/.docs/docs/memory/observational-memory.md +65 -8
- package/.docs/docs/memory/storage.md +1 -2
- package/.docs/docs/memory/working-memory.md +2 -2
- package/.docs/docs/observability/logging.md +1 -1
- package/.docs/docs/observability/metrics/overview.md +2 -2
- package/.docs/docs/observability/overview.md +1 -1
- package/.docs/docs/observability/tracing/bridges/datadog.md +217 -0
- package/.docs/docs/observability/tracing/bridges/otel.md +2 -2
- package/.docs/docs/observability/tracing/exporters/arthur.md +163 -0
- package/.docs/docs/observability/tracing/exporters/cloud.md +135 -63
- package/.docs/docs/observability/tracing/exporters/datadog.md +3 -1
- package/.docs/docs/observability/tracing/exporters/default.md +5 -5
- package/.docs/docs/observability/tracing/exporters/laminar.md +22 -14
- package/.docs/docs/observability/tracing/exporters/langfuse.md +50 -33
- package/.docs/docs/observability/tracing/overview.md +87 -20
- package/.docs/docs/server/custom-adapters.md +5 -5
- package/.docs/docs/server/custom-api-routes.md +3 -3
- package/.docs/docs/server/mastra-client.md +2 -2
- package/.docs/docs/server/mastra-server.md +1 -1
- package/.docs/docs/server/middleware.md +46 -42
- package/.docs/docs/server/request-context.md +13 -2
- package/.docs/docs/server/server-adapters.md +91 -8
- package/.docs/docs/streaming/background-task-streaming.md +80 -0
- package/.docs/docs/streaming/overview.md +3 -0
- package/.docs/docs/studio/deployment.md +24 -6
- package/.docs/docs/studio/observability.md +1 -1
- package/.docs/docs/studio/overview.md +4 -4
- package/.docs/docs/voice/overview.md +74 -5
- package/.docs/docs/voice/speech-to-speech.md +45 -1
- package/.docs/docs/voice/speech-to-text.md +7 -7
- package/.docs/docs/voice/text-to-speech.md +10 -10
- package/.docs/docs/workflows/agents-and-tools.md +1 -1
- package/.docs/docs/workflows/overview.md +105 -4
- package/.docs/docs/workflows/scheduled-workflows.md +181 -0
- package/.docs/docs/workspace/filesystem.md +64 -6
- package/.docs/docs/workspace/lsp.md +76 -4
- package/.docs/docs/workspace/overview.md +62 -15
- package/.docs/docs/workspace/sandbox.md +3 -1
- package/.docs/docs/workspace/search.md +41 -2
- package/.docs/docs/workspace/skills.md +19 -19
- package/.docs/guides/agent-frameworks/ai-sdk.md +4 -4
- package/.docs/guides/build-your-ui/ai-sdk-ui.md +56 -9
- package/.docs/guides/build-your-ui/assistant-ui.md +1 -1
- package/.docs/guides/deployment/mastra-platform.md +191 -0
- package/.docs/guides/deployment/netlify.md +16 -1
- package/.docs/guides/getting-started/nestjs.md +238 -0
- package/.docs/guides/getting-started/next-js.md +0 -4
- package/.docs/guides/guide/code-review-bot.md +2 -2
- package/.docs/guides/guide/dev-assistant.md +4 -4
- package/.docs/{docs/mcp → guides/guide}/publishing-mcp-server.md +21 -1
- package/.docs/guides/guide/slack-assistant.md +191 -0
- package/.docs/guides/migrations/mastra-cloud.md +368 -0
- package/.docs/guides/migrations/upgrade-to-v1/tracing.md +1 -1
- package/.docs/models/embeddings.md +3 -3
- package/.docs/models/gateways/azure-openai.md +74 -35
- package/.docs/models/gateways/mastra.md +64 -0
- package/.docs/models/gateways/netlify.md +7 -3
- package/.docs/models/gateways/openrouter.md +28 -12
- package/.docs/models/gateways/vercel.md +22 -2
- package/.docs/models/gateways.md +1 -0
- package/.docs/models/index.md +43 -8
- package/.docs/models/providers/302ai.md +37 -4
- package/.docs/models/providers/abliteration-ai.md +71 -0
- package/.docs/models/providers/alibaba-cn.md +8 -2
- package/.docs/models/providers/alibaba-coding-plan-cn.md +3 -2
- package/.docs/models/providers/alibaba-coding-plan.md +3 -2
- package/.docs/models/providers/alibaba.md +8 -1
- package/.docs/models/providers/anthropic.md +18 -5
- package/.docs/models/providers/baseten.md +3 -1
- package/.docs/models/providers/berget.md +10 -12
- package/.docs/models/providers/chutes.md +4 -2
- package/.docs/models/providers/cloudflare-workers-ai.md +14 -48
- package/.docs/models/providers/cortecs.md +22 -2
- package/.docs/models/providers/deepinfra.md +8 -2
- package/.docs/models/providers/deepseek.md +6 -4
- package/.docs/models/providers/digitalocean.md +133 -0
- package/.docs/models/providers/fireworks-ai.md +6 -1
- package/.docs/models/providers/firmware.md +12 -10
- package/.docs/models/providers/friendli.md +6 -7
- package/.docs/models/providers/google.md +9 -3
- package/.docs/models/providers/helicone.md +1 -2
- package/.docs/models/providers/hpc-ai.md +73 -0
- package/.docs/models/providers/huggingface.md +6 -2
- package/.docs/models/providers/inception.md +9 -11
- package/.docs/models/providers/kilo.md +359 -339
- package/.docs/models/providers/kimi-for-coding.md +2 -1
- package/.docs/models/providers/llmgateway.md +67 -77
- package/.docs/models/providers/mistral.md +3 -2
- package/.docs/models/providers/mixlayer.md +75 -0
- package/.docs/models/providers/moonshotai-cn.md +3 -2
- package/.docs/models/providers/moonshotai.md +3 -2
- package/.docs/models/providers/nano-gpt.md +8 -2
- package/.docs/models/providers/neuralwatt.md +84 -0
- package/.docs/models/providers/novita-ai.md +19 -4
- package/.docs/models/providers/nvidia.md +8 -1
- package/.docs/models/providers/ollama-cloud.md +7 -2
- package/.docs/models/providers/openai.md +7 -2
- package/.docs/models/providers/opencode-go.md +21 -13
- package/.docs/models/providers/opencode.md +11 -4
- package/.docs/models/providers/ovhcloud.md +6 -8
- package/.docs/models/providers/poe.md +10 -15
- package/.docs/models/providers/regolo-ai.md +83 -0
- package/.docs/models/providers/siliconflow-cn.md +5 -2
- package/.docs/models/providers/siliconflow.md +6 -3
- package/.docs/models/providers/stepfun.md +8 -7
- package/.docs/models/providers/synthetic.md +5 -2
- package/.docs/models/providers/tencent-token-plan.md +71 -0
- package/.docs/models/providers/tencent-tokenhub.md +71 -0
- package/.docs/models/providers/togetherai.md +8 -7
- package/.docs/models/providers/vivgrid.md +7 -3
- package/.docs/models/providers/vultr.md +7 -6
- package/.docs/models/providers/wafer.ai.md +73 -0
- package/.docs/models/providers/wandb.md +3 -2
- package/.docs/models/providers/xai.md +6 -1
- package/.docs/models/providers/xiaomi-token-plan-ams.md +75 -0
- package/.docs/models/providers/xiaomi-token-plan-cn.md +75 -0
- package/.docs/models/providers/xiaomi-token-plan-sgp.md +75 -0
- package/.docs/models/providers/xiaomi.md +4 -2
- package/.docs/models/providers/zai-coding-plan.md +11 -19
- package/.docs/models/providers/zai.md +2 -1
- package/.docs/models/providers/zenmux.md +17 -6
- package/.docs/models/providers/zhipuai-coding-plan.md +11 -21
- package/.docs/models/providers/zhipuai.md +2 -1
- package/.docs/models/providers.md +11 -0
- package/.docs/reference/agents/agent.md +1 -1
- package/.docs/reference/agents/channels.md +3 -3
- package/.docs/reference/agents/generate.md +88 -6
- package/.docs/reference/agents/generateLegacy.md +1 -1
- package/.docs/reference/ai-sdk/chat-route.md +2 -0
- package/.docs/reference/ai-sdk/handle-chat-stream.md +19 -0
- package/.docs/reference/ai-sdk/handle-network-stream.md +2 -0
- package/.docs/reference/ai-sdk/network-route.md +2 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-messages.md +95 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-stream.md +15 -0
- package/.docs/reference/browser/agent-browser.md +375 -0
- package/.docs/reference/browser/browser-viewer.md +228 -0
- package/.docs/reference/browser/mastra-browser.md +286 -0
- package/.docs/reference/browser/stagehand-browser.md +286 -0
- package/.docs/reference/cli/mastra.md +703 -0
- package/.docs/reference/client-js/agents.md +166 -0
- package/.docs/reference/client-js/conversations.md +1 -1
- package/.docs/reference/client-js/mastra-client.md +23 -0
- package/.docs/reference/client-js/observability.md +2 -2
- package/.docs/reference/client-js/responses.md +1 -1
- package/.docs/reference/client-js/workflows.md +62 -1
- package/.docs/reference/configuration.md +67 -1
- package/.docs/reference/core/addGateway.md +5 -5
- package/.docs/reference/core/getEditor.md +35 -0
- package/.docs/reference/core/getGateway.md +5 -5
- package/.docs/reference/core/getGatewayById.md +5 -5
- package/.docs/reference/core/getMCPServer.md +2 -2
- package/.docs/reference/core/getMCPServerById.md +2 -2
- package/.docs/reference/core/getScorer.md +3 -3
- package/.docs/reference/core/getScorerById.md +3 -3
- package/.docs/reference/core/listGateways.md +5 -5
- package/.docs/reference/core/listMCPServers.md +2 -2
- package/.docs/reference/core/listScorers.md +3 -3
- package/.docs/reference/core/mastra-class.md +11 -1
- package/.docs/reference/core/mastra-model-gateway.md +5 -5
- package/.docs/reference/datasets/create.md +4 -4
- package/.docs/reference/datasets/startExperiment.md +28 -2
- package/.docs/reference/datasets/update.md +4 -4
- package/.docs/reference/deployer/cloudflare.md +14 -1
- package/.docs/reference/deployer/netlify.md +50 -2
- package/.docs/reference/editor/mastra-editor.md +168 -0
- package/.docs/reference/editor/tool-provider.md +85 -0
- package/.docs/reference/evals/context-precision.md +3 -3
- package/.docs/reference/evals/context-relevance.md +3 -3
- package/.docs/reference/evals/create-scorer.md +5 -3
- package/.docs/reference/evals/filter-run.md +117 -0
- package/.docs/reference/evals/mastra-scorer.md +4 -4
- package/.docs/reference/evals/noise-sensitivity.md +6 -6
- package/.docs/reference/evals/prompt-alignment.md +12 -12
- package/.docs/reference/evals/run-evals.md +6 -6
- package/.docs/reference/evals/scorer-utils.md +3 -3
- package/.docs/reference/evals/trajectory-accuracy.md +3 -3
- package/.docs/reference/harness/harness-class.md +152 -53
- package/.docs/reference/index.md +25 -0
- package/.docs/reference/logging/pino-logger.md +0 -2
- package/.docs/reference/mastra-platform/api.md +108 -0
- package/.docs/reference/memory/clone-utilities.md +4 -2
- package/.docs/reference/memory/cloneThread.md +4 -2
- package/.docs/reference/memory/observational-memory.md +4 -0
- package/.docs/reference/observability/metrics/automatic-metrics.md +3 -3
- package/.docs/reference/observability/tracing/bridges/datadog.md +211 -0
- package/.docs/reference/observability/tracing/bridges/otel.md +3 -3
- package/.docs/reference/observability/tracing/configuration.md +18 -11
- package/.docs/reference/observability/tracing/exporters/arthur.md +122 -0
- package/.docs/reference/observability/tracing/exporters/cloud-exporter.md +102 -21
- package/.docs/reference/observability/tracing/exporters/console-exporter.md +8 -8
- package/.docs/reference/observability/tracing/exporters/datadog.md +3 -1
- package/.docs/reference/observability/tracing/exporters/default-exporter.md +8 -8
- package/.docs/reference/observability/tracing/exporters/langfuse.md +25 -32
- package/.docs/reference/observability/tracing/exporters/otel.md +3 -3
- package/.docs/reference/observability/tracing/instances.md +7 -7
- package/.docs/reference/observability/tracing/interfaces.md +23 -6
- package/.docs/reference/observability/tracing/span-filtering.md +95 -0
- package/.docs/reference/observability/tracing/spans.md +6 -6
- package/.docs/reference/processors/prefill-error-handler.md +70 -0
- package/.docs/reference/processors/processor-interface.md +400 -40
- package/.docs/reference/processors/skill-search-processor.md +20 -1
- package/.docs/reference/processors/stream-error-retry-processor.md +54 -0
- package/.docs/reference/processors/tool-call-filter.md +23 -0
- package/.docs/reference/server/create-route.md +3 -3
- package/.docs/reference/server/express-adapter.md +4 -4
- package/.docs/reference/server/fastify-adapter.md +4 -4
- package/.docs/reference/server/hono-adapter.md +4 -4
- package/.docs/reference/server/koa-adapter.md +4 -4
- package/.docs/reference/server/mastra-server.md +3 -3
- package/.docs/reference/server/nestjs-adapter.md +169 -0
- package/.docs/reference/server/register-api-route.md +4 -4
- package/.docs/reference/server/routes.md +11 -10
- package/.docs/reference/storage/clickhouse.md +300 -0
- package/.docs/reference/storage/cloudflare-d1.md +42 -42
- package/.docs/reference/storage/composite.md +5 -3
- package/.docs/reference/storage/duckdb.md +150 -0
- package/.docs/reference/storage/overview.md +1 -1
- package/.docs/reference/storage/redis.md +266 -0
- package/.docs/reference/streaming/ChunkType.md +143 -3
- package/.docs/reference/streaming/agents/MastraModelOutput.md +2 -2
- package/.docs/reference/streaming/agents/stream.md +10 -2
- package/.docs/reference/streaming/agents/streamUntilIdle.md +94 -0
- package/.docs/reference/streaming/workflows/resumeStream.md +2 -0
- package/.docs/reference/templates/overview.md +88 -14
- package/.docs/reference/tools/create-tool.md +107 -5
- package/.docs/reference/tools/mcp-client.md +45 -0
- package/.docs/reference/tools/mcp-server.md +1 -3
- package/.docs/reference/tools/perplexity.md +155 -0
- package/.docs/reference/tools/tavily.md +307 -0
- package/.docs/reference/vectors/mongodb.md +0 -2
- package/.docs/reference/voice/aws-nova-sonic.md +247 -0
- package/.docs/reference/voice/cloudflare.md +3 -3
- package/.docs/reference/voice/sarvam.md +29 -23
- package/.docs/reference/voice/voice.connect.md +4 -4
- package/.docs/reference/voice/voice.listen.md +3 -3
- package/.docs/reference/workflows/run-methods/resume.md +24 -0
- package/.docs/reference/workflows/run-methods/startAsync.md +1 -1
- package/.docs/reference/workflows/step.md +88 -7
- package/.docs/reference/workflows/workflow-methods/foreach.md +14 -1
- package/.docs/reference/workflows/workflow.md +88 -4
- package/.docs/reference/workspace/azure-blob-filesystem.md +219 -0
- package/.docs/reference/workspace/docker-sandbox.md +196 -0
- package/.docs/reference/workspace/gcs-filesystem.md +1 -0
- package/.docs/reference/workspace/google-drive-filesystem.md +185 -0
- package/.docs/reference/workspace/modal-sandbox.md +168 -0
- package/.docs/reference/workspace/process-manager.md +1 -1
- package/.docs/reference/workspace/s3-filesystem.md +80 -5
- package/.docs/reference/workspace/vercel.md +1 -1
- package/.docs/reference/workspace/workspace-class.md +37 -6
- package/CHANGELOG.md +500 -4
- package/dist/stdio.js.map +1 -1
- package/dist/utils.d.ts +1 -4
- package/dist/utils.d.ts.map +1 -1
- package/package.json +11 -11
- package/.docs/docs/mastra-cloud/deployment.md +0 -77
- package/.docs/docs/mastra-cloud/observability.md +0 -38
- package/.docs/docs/mastra-cloud/overview.md +0 -23
- package/.docs/docs/mastra-cloud/setup.md +0 -42
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# DockerSandbox
|
|
2
|
+
|
|
3
|
+
Executes commands inside Docker containers on the local machine. Uses long-lived containers with `docker exec` for command execution. Targets local development, CI/CD, air-gapped deployments, and cost-sensitive scenarios where cloud sandboxes are unnecessary.
|
|
4
|
+
|
|
5
|
+
> **Info:** For interface details, see [WorkspaceSandbox interface](https://mastra.ai/reference/workspace/sandbox).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
**npm**:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @mastra/docker
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**pnpm**:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @mastra/docker
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Yarn**:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
yarn add @mastra/docker
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Bun**:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bun add @mastra/docker
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Requires [Docker Engine](https://docs.docker.com/engine/install/) running on the host machine.
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
Add a `DockerSandbox` to a workspace and assign it to an agent:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { Agent } from '@mastra/core/agent'
|
|
41
|
+
import { Workspace } from '@mastra/core/workspace'
|
|
42
|
+
import { DockerSandbox } from '@mastra/docker'
|
|
43
|
+
|
|
44
|
+
const workspace = new Workspace({
|
|
45
|
+
sandbox: new DockerSandbox({
|
|
46
|
+
image: 'node:22-slim',
|
|
47
|
+
}),
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const agent = new Agent({
|
|
51
|
+
name: 'dev-agent',
|
|
52
|
+
model: 'anthropic/claude-opus-4-6',
|
|
53
|
+
workspace,
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Constructor parameters
|
|
58
|
+
|
|
59
|
+
**id** (`string`): Unique identifier for this sandbox instance. Used for container naming and reconnection via labels. (Default: `Auto-generated`)
|
|
60
|
+
|
|
61
|
+
**image** (`string`): Docker image to use for the container. (Default: `'node:22-slim'`)
|
|
62
|
+
|
|
63
|
+
**command** (`string[]`): Container entrypoint command. Must keep the container alive for exec-based command execution. (Default: `['sleep', 'infinity']`)
|
|
64
|
+
|
|
65
|
+
**env** (`Record<string, string>`): Environment variables to set in the container.
|
|
66
|
+
|
|
67
|
+
**volumes** (`Record<string, string>`): Host-to-container bind mounts. Keys are host paths, values are container paths.
|
|
68
|
+
|
|
69
|
+
**network** (`string`): Docker network to join.
|
|
70
|
+
|
|
71
|
+
**privileged** (`boolean`): Run in privileged mode. (Default: `false`)
|
|
72
|
+
|
|
73
|
+
**workingDir** (`string`): Working directory inside the container. (Default: `'/workspace'`)
|
|
74
|
+
|
|
75
|
+
**labels** (`Record<string, string>`): Additional container labels. Mastra labels (mastra.sandbox, mastra.sandbox.id) are always included.
|
|
76
|
+
|
|
77
|
+
**timeout** (`number`): Default command timeout in milliseconds. (Default: `300000 (5 minutes)`)
|
|
78
|
+
|
|
79
|
+
**dockerOptions** (`Docker.DockerOptions`): Pass-through dockerode connection options for custom socket paths, remote hosts, or TLS certificates.
|
|
80
|
+
|
|
81
|
+
**instructions** (`string | function`): Custom instructions that override the default instructions returned by getInstructions(). Pass an empty string to suppress instructions.
|
|
82
|
+
|
|
83
|
+
## Properties
|
|
84
|
+
|
|
85
|
+
**id** (`string`): Sandbox instance identifier.
|
|
86
|
+
|
|
87
|
+
**name** (`string`): Provider name ('DockerSandbox').
|
|
88
|
+
|
|
89
|
+
**provider** (`string`): Provider identifier ('docker').
|
|
90
|
+
|
|
91
|
+
**status** (`ProviderStatus`): 'pending' | 'starting' | 'running' | 'stopping' | 'stopped' | 'destroying' | 'destroyed' | 'error'
|
|
92
|
+
|
|
93
|
+
**container** (`Container`): The underlying dockerode Container instance. Throws SandboxNotReadyError if the sandbox has not been started.
|
|
94
|
+
|
|
95
|
+
**processes** (`DockerProcessManager`): Background process manager. See \[SandboxProcessManager reference]\(/reference/workspace/process-manager).
|
|
96
|
+
|
|
97
|
+
## Background processes
|
|
98
|
+
|
|
99
|
+
`DockerSandbox` includes a built-in process manager for spawning and managing background processes. Processes run inside the container using `docker exec`.
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
const sandbox = new DockerSandbox({ id: 'dev-sandbox' })
|
|
103
|
+
await sandbox._start()
|
|
104
|
+
|
|
105
|
+
// Spawn a background process
|
|
106
|
+
const handle = await sandbox.processes.spawn('node server.js', {
|
|
107
|
+
env: { PORT: '3000' },
|
|
108
|
+
onStdout: data => console.log(data),
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
// Interact with the process
|
|
112
|
+
console.log(handle.stdout)
|
|
113
|
+
await handle.sendStdin('input\n')
|
|
114
|
+
await handle.kill()
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
See [`SandboxProcessManager` reference](https://mastra.ai/reference/workspace/process-manager) for the full API.
|
|
118
|
+
|
|
119
|
+
## Environment variables
|
|
120
|
+
|
|
121
|
+
Set environment variables at the container level with `env`. Per-command environment variables can also be passed when spawning processes:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
const sandbox = new DockerSandbox({
|
|
125
|
+
image: 'node:22-slim',
|
|
126
|
+
env: {
|
|
127
|
+
NODE_ENV: 'production',
|
|
128
|
+
DATABASE_URL: 'postgres://localhost:5432/mydb',
|
|
129
|
+
},
|
|
130
|
+
})
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Bind mounts
|
|
134
|
+
|
|
135
|
+
Mount host directories into the container using the `volumes` option:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
const sandbox = new DockerSandbox({
|
|
139
|
+
image: 'node:22-slim',
|
|
140
|
+
volumes: {
|
|
141
|
+
'/my/project': '/workspace/project',
|
|
142
|
+
'/shared/data': '/data',
|
|
143
|
+
},
|
|
144
|
+
})
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Bind mounts are applied at container creation time. The host paths must exist before the sandbox starts.
|
|
148
|
+
|
|
149
|
+
## Reconnection
|
|
150
|
+
|
|
151
|
+
`DockerSandbox` can reconnect to existing containers by matching labels. When `start()` is called, it checks for a container with the `mastra.sandbox.id` label matching the sandbox ID. If found:
|
|
152
|
+
|
|
153
|
+
- A running container is reused directly.
|
|
154
|
+
- A stopped container is restarted.
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
// First run — creates a new container
|
|
158
|
+
const sandbox = new DockerSandbox({ id: 'persistent-sandbox' })
|
|
159
|
+
await sandbox._start()
|
|
160
|
+
|
|
161
|
+
// Later — reconnects to the existing container
|
|
162
|
+
const sandbox2 = new DockerSandbox({ id: 'persistent-sandbox' })
|
|
163
|
+
await sandbox2._start()
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Docker connection options
|
|
167
|
+
|
|
168
|
+
Connect to remote Docker hosts or use custom socket paths via `dockerOptions`:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
// Remote Docker host
|
|
172
|
+
const sandbox = new DockerSandbox({
|
|
173
|
+
dockerOptions: {
|
|
174
|
+
host: '192.168.1.100',
|
|
175
|
+
port: 2376,
|
|
176
|
+
ca: fs.readFileSync('ca.pem'),
|
|
177
|
+
cert: fs.readFileSync('cert.pem'),
|
|
178
|
+
key: fs.readFileSync('key.pem'),
|
|
179
|
+
},
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
// Custom socket path
|
|
183
|
+
const sandbox = new DockerSandbox({
|
|
184
|
+
dockerOptions: {
|
|
185
|
+
socketPath: '/var/run/docker.sock',
|
|
186
|
+
},
|
|
187
|
+
})
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Related
|
|
191
|
+
|
|
192
|
+
- [SandboxProcessManager reference](https://mastra.ai/reference/workspace/process-manager)
|
|
193
|
+
- [WorkspaceSandbox interface](https://mastra.ai/reference/workspace/sandbox)
|
|
194
|
+
- [LocalSandbox reference](https://mastra.ai/reference/workspace/local-sandbox)
|
|
195
|
+
- [E2BSandbox reference](https://mastra.ai/reference/workspace/e2b-sandbox)
|
|
196
|
+
- [Workspace overview](https://mastra.ai/docs/workspace/overview)
|
|
@@ -190,5 +190,6 @@ See [E2BSandbox reference](https://mastra.ai/reference/workspace/e2b-sandbox) fo
|
|
|
190
190
|
|
|
191
191
|
- [WorkspaceFilesystem interface](https://mastra.ai/reference/workspace/filesystem)
|
|
192
192
|
- [S3Filesystem reference](https://mastra.ai/reference/workspace/s3-filesystem)
|
|
193
|
+
- [AzureBlobFilesystem reference](https://mastra.ai/reference/workspace/azure-blob-filesystem)
|
|
193
194
|
- [E2BSandbox reference](https://mastra.ai/reference/workspace/e2b-sandbox)
|
|
194
195
|
- [Workspace overview](https://mastra.ai/docs/workspace/overview)
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# GoogleDriveFilesystem
|
|
2
|
+
|
|
3
|
+
Stores files in a single Google Drive folder. Each directory maps to a Drive folder under the configured root, and paths use POSIX semantics (for example `/notes/todo.txt`).
|
|
4
|
+
|
|
5
|
+
> **Info:** For interface details, see [WorkspaceFilesystem Interface](https://mastra.ai/reference/workspace/filesystem).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
**npm**:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @mastra/google-drive
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**pnpm**:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @mastra/google-drive
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Yarn**:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
yarn add @mastra/google-drive
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Bun**:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bun add @mastra/google-drive
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
Add a `GoogleDriveFilesystem` to a workspace and assign it to an agent:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { Agent } from '@mastra/core/agent'
|
|
39
|
+
import { Workspace } from '@mastra/core/workspace'
|
|
40
|
+
import { GoogleDriveFilesystem } from '@mastra/google-drive'
|
|
41
|
+
|
|
42
|
+
const workspace = new Workspace({
|
|
43
|
+
filesystem: new GoogleDriveFilesystem({
|
|
44
|
+
folderId: process.env.GOOGLE_DRIVE_FOLDER_ID!,
|
|
45
|
+
accessToken: process.env.GOOGLE_DRIVE_ACCESS_TOKEN!,
|
|
46
|
+
}),
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const agent = new Agent({
|
|
50
|
+
id: 'drive-agent',
|
|
51
|
+
name: 'Drive Agent',
|
|
52
|
+
model: 'openai/gpt-4o-mini',
|
|
53
|
+
workspace,
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Authentication
|
|
58
|
+
|
|
59
|
+
Supply one of the following authentication options:
|
|
60
|
+
|
|
61
|
+
- **`accessToken`**: A pre-obtained OAuth access token. Use the `https://www.googleapis.com/auth/drive` scope so the token can see folders shared with the authenticated identity.
|
|
62
|
+
- **`getAccessToken`**: A callback that returns a token. Useful when tokens are refreshed externally.
|
|
63
|
+
- **`serviceAccount`**: A Google service account. Share the target folder with the service account email.
|
|
64
|
+
|
|
65
|
+
#### Service account
|
|
66
|
+
|
|
67
|
+
Service account auth is the recommended option for backend agents. There is no user consent flow and no token refresh handling. You only need **two values** from the service account JSON key file: `client_email` and `private_key`.
|
|
68
|
+
|
|
69
|
+
##### Set up the service account
|
|
70
|
+
|
|
71
|
+
1. Open the [Google Cloud Console](https://console.cloud.google.com/) and select or create a project.
|
|
72
|
+
2. Go to **APIs & Services > Library**, search for **Google Drive API**, and select **Enable**.
|
|
73
|
+
3. Go to **APIs & Services > Credentials**, select **Create credentials > Service account**, and complete the form. The role can be left blank — Drive permissions are granted by sharing folders, not by IAM roles.
|
|
74
|
+
4. Open the new service account, go to the **Keys** tab, and select **Add key > Create new key > JSON**. The browser downloads a JSON key file.
|
|
75
|
+
5. Copy the `client_email` value from the JSON file. This is the address you share Drive folders with.
|
|
76
|
+
|
|
77
|
+
##### Share the Drive folder with the service account
|
|
78
|
+
|
|
79
|
+
The service account is its own Google identity. It cannot see anything in Drive until you share with it explicitly.
|
|
80
|
+
|
|
81
|
+
1. Open the target folder in [Google Drive](https://drive.google.com/).
|
|
82
|
+
2. Select **Share**.
|
|
83
|
+
3. Paste the service account's `client_email` address.
|
|
84
|
+
4. Set the role to **Editor** (for read and write) or **Viewer** (for read-only access). Select **Send**.
|
|
85
|
+
5. Copy the folder ID from the URL. It is the segment after `/folders/` in `https://drive.google.com/drive/folders/<folderId>`.
|
|
86
|
+
|
|
87
|
+
> **Warning:** Service accounts cannot create files in standard "My Drive" folders. A service account has no personal Drive storage quota, so any file it creates needs to be owned by a quota-bearing entity. If you only share a personal Drive folder, read operations work but writes fail with a quota error.
|
|
88
|
+
>
|
|
89
|
+
> For write access, place the folder inside a **shared drive** (formerly Team Drive) and add the service account as a member of that shared drive. Shared drives provide the storage quota that service-account-created files need.
|
|
90
|
+
>
|
|
91
|
+
> Read-only workloads against a personal Drive folder do not have this restriction.
|
|
92
|
+
|
|
93
|
+
##### Configure the filesystem
|
|
94
|
+
|
|
95
|
+
Copy `client_email` and `private_key` from the JSON file into your environment:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
GOOGLE_DRIVE_FOLDER_ID=1AbCdEfGhIjKlMnOpQrStUvWxYz
|
|
99
|
+
GOOGLE_DRIVE_CLIENT_EMAIL=my-bot@my-project.iam.gserviceaccount.com
|
|
100
|
+
# Wrap the value in quotes — the key contains newlines that must be preserved.
|
|
101
|
+
GOOGLE_DRIVE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkq...\n-----END PRIVATE KEY-----\n"
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { GoogleDriveFilesystem } from '@mastra/google-drive'
|
|
106
|
+
|
|
107
|
+
const filesystem = new GoogleDriveFilesystem({
|
|
108
|
+
folderId: process.env.GOOGLE_DRIVE_FOLDER_ID!,
|
|
109
|
+
serviceAccount: {
|
|
110
|
+
clientEmail: process.env.GOOGLE_DRIVE_CLIENT_EMAIL!,
|
|
111
|
+
privateKey: process.env.GOOGLE_DRIVE_PRIVATE_KEY!,
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
You do **not** need to copy the entire JSON file or pass other fields like `project_id`, `client_id`, `private_key_id`, or `token_uri`. They are not used. Only `clientEmail` and `privateKey` are required. `privateKeyId`, `scopes`, and `subject` are optional. `scopes` defaults to `['https://www.googleapis.com/auth/drive']`, which is the scope required for the service account to see folders shared with it. The narrower `drive.file` scope only grants access to files the application created itself, so a folder shared with the service account would return `404 Not Found`.
|
|
117
|
+
|
|
118
|
+
`GoogleDriveFilesystem` automatically normalizes the `privateKey` string before signing. It strips surrounding quotes (including escaped quotes from JSON-wrapped values), converts literal `\n` sequences to real newlines, normalizes `\r\n` line endings, and removes a trailing comma. The key works regardless of how your `.env` loader handles the value.
|
|
119
|
+
|
|
120
|
+
##### Troubleshoot
|
|
121
|
+
|
|
122
|
+
- **`404 File not found: <folderId>`**: The service account does not have access to the folder. Confirm the folder is shared with the exact `client_email` address and that the folder ID matches the URL.
|
|
123
|
+
- **`storageQuotaExceeded` on write**: The folder is in a personal "My Drive". Move the folder to a shared drive and add the service account as a member.
|
|
124
|
+
- **`error:1E08010C:DECODER routines::unsupported`**: The `privateKey` value is malformed. Confirm the value contains the full PEM block and that newlines are preserved (literal `\n` is fine).
|
|
125
|
+
|
|
126
|
+
### Read-only mode
|
|
127
|
+
|
|
128
|
+
Pass `readOnly: true` to block write operations (`writeFile`, `appendFile`, `deleteFile`, `copyFile`, `moveFile`, `mkdir`, `rmdir`).
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
const filesystem = new GoogleDriveFilesystem({
|
|
132
|
+
folderId,
|
|
133
|
+
accessToken,
|
|
134
|
+
readOnly: true,
|
|
135
|
+
})
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Constructor parameters
|
|
139
|
+
|
|
140
|
+
**folderId** (`string`): ID of the Google Drive folder that acts as the workspace root. All paths are resolved inside this folder.
|
|
141
|
+
|
|
142
|
+
**accessToken** (`string`): OAuth access token with access to the folder.
|
|
143
|
+
|
|
144
|
+
**getAccessToken** (`() => string | Promise<string>`): Callback that returns a fresh OAuth access token. Called on every request that needs authorization.
|
|
145
|
+
|
|
146
|
+
**serviceAccount** (`{ clientEmail: string; privateKey: string; privateKeyId?: string; scopes?: string[]; subject?: string }`): Service account credentials used to mint access tokens via the OAuth 2.0 JWT flow.
|
|
147
|
+
|
|
148
|
+
**id** (`string`): Unique identifier for this filesystem instance (Default: `` `google-drive:${folderId}` ``)
|
|
149
|
+
|
|
150
|
+
**readOnly** (`boolean`): When true, all write operations are blocked. (Default: `false`)
|
|
151
|
+
|
|
152
|
+
**instructions** (`InstructionsOption`): Override the default instructions returned to tool descriptions.
|
|
153
|
+
|
|
154
|
+
## Properties
|
|
155
|
+
|
|
156
|
+
**id** (`string`): Filesystem instance identifier
|
|
157
|
+
|
|
158
|
+
**name** (`string`): Provider name ('GoogleDriveFilesystem')
|
|
159
|
+
|
|
160
|
+
**provider** (`string`): Provider identifier ('google-drive')
|
|
161
|
+
|
|
162
|
+
**readOnly** (`boolean | undefined`): Whether the filesystem is in read-only mode
|
|
163
|
+
|
|
164
|
+
## Methods
|
|
165
|
+
|
|
166
|
+
GoogleDriveFilesystem implements the [WorkspaceFilesystem interface](https://mastra.ai/reference/workspace/filesystem), providing all standard filesystem methods:
|
|
167
|
+
|
|
168
|
+
- `readFile(path, options?)` - Download file contents
|
|
169
|
+
- `writeFile(path, content, options?)` - Upload or overwrite a file
|
|
170
|
+
- `appendFile(path, content)` - Append content by reading and re-uploading the file
|
|
171
|
+
- `deleteFile(path, options?)` - Delete a file
|
|
172
|
+
- `copyFile(src, dest, options?)` - Copy a file using the Drive `files.copy` API
|
|
173
|
+
- `moveFile(src, dest, options?)` - Move a file between folders by swapping parents
|
|
174
|
+
- `mkdir(path, options?)` - Create a folder
|
|
175
|
+
- `rmdir(path, options?)` - Remove a folder
|
|
176
|
+
- `readdir(path, options?)` - List folder contents (supports `recursive` and `extension` filtering)
|
|
177
|
+
- `stat(path)` - Return Drive metadata for a file or folder
|
|
178
|
+
- `exists(path)` - Check if a file or folder exists
|
|
179
|
+
|
|
180
|
+
## Notes
|
|
181
|
+
|
|
182
|
+
- Google Drive allows multiple files with the same name in a folder. `GoogleDriveFilesystem` resolves paths by picking the first match, so keep names unique within each folder when you rely on path-based lookup.
|
|
183
|
+
- `writeFile` creates parent folders automatically when `recursive` is unset (the default) or `true`. Set `recursive: false` to require the parent folder to already exist.
|
|
184
|
+
- `expectedMtime` on `WriteOptions` is honored — when the stored `modifiedTime` differs, the write is rejected with `StaleFileError` to support optimistic concurrency.
|
|
185
|
+
- The provider only exercises Drive REST endpoints (`https://www.googleapis.com/drive/v3` and `https://www.googleapis.com/upload/drive/v3`) through the built-in `fetch`; no additional dependencies are required.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# ModalSandbox
|
|
2
|
+
|
|
3
|
+
Executes commands in isolated [Modal](https://modal.com) cloud sandboxes. Provides secure, ephemeral environments backed by Modal's infrastructure.
|
|
4
|
+
|
|
5
|
+
> **Info:** For interface details, see [WorkspaceSandbox interface](https://mastra.ai/reference/workspace/sandbox).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
**npm**:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @mastra/modal
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**pnpm**:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @mastra/modal
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Yarn**:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
yarn add @mastra/modal
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Bun**:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bun add @mastra/modal
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
Add a `ModalSandbox` to a workspace and assign it to an agent:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { Agent } from '@mastra/core/agent'
|
|
39
|
+
import { Workspace } from '@mastra/core/workspace'
|
|
40
|
+
import { ModalSandbox } from '@mastra/modal'
|
|
41
|
+
|
|
42
|
+
const workspace = new Workspace({
|
|
43
|
+
sandbox: new ModalSandbox({
|
|
44
|
+
id: 'dev-sandbox',
|
|
45
|
+
baseImage: 'ubuntu:22.04',
|
|
46
|
+
timeoutMs: 60_000,
|
|
47
|
+
}),
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const agent = new Agent({
|
|
51
|
+
id: 'dev-agent',
|
|
52
|
+
model: 'anthropic/claude-opus-4-6',
|
|
53
|
+
workspace,
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Authentication
|
|
58
|
+
|
|
59
|
+
Set Modal credentials via environment variables or constructor options:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
MODAL_TOKEN_ID=ak-...
|
|
63
|
+
MODAL_TOKEN_SECRET=as-...
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Or pass them directly:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
const sandbox = new ModalSandbox({
|
|
70
|
+
tokenId: process.env.MODAL_TOKEN_ID,
|
|
71
|
+
tokenSecret: process.env.MODAL_TOKEN_SECRET,
|
|
72
|
+
})
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Get your credentials from the [Modal dashboard](https://modal.com/settings/tokens).
|
|
76
|
+
|
|
77
|
+
## Constructor parameters
|
|
78
|
+
|
|
79
|
+
**id** (`string`): Unique identifier / name for this sandbox. Used as the Modal sandbox name so the sandbox can be reconnected on subsequent start() calls. (Default: `Auto-generated`)
|
|
80
|
+
|
|
81
|
+
**appName** (`string`): Modal App name to associate sandboxes with. (Default: `'mastra'`)
|
|
82
|
+
|
|
83
|
+
**baseImage** (`string`): Docker image to use for the sandbox. (Default: `'ubuntu:22.04'`)
|
|
84
|
+
|
|
85
|
+
**timeoutMs** (`number`): Wall-clock max lifetime in milliseconds. The sandbox is terminated when this expires, regardless of activity. Modal's maximum is 24 hours (86\_400\_000). (Default: `300000 (5 minutes)`)
|
|
86
|
+
|
|
87
|
+
**env** (`Record<string, string>`): Environment variables baked into the sandbox at create time.
|
|
88
|
+
|
|
89
|
+
**workdir** (`string`): Default working directory inside the sandbox.
|
|
90
|
+
|
|
91
|
+
**tokenId** (`string`): Modal token ID. Falls back to MODAL\_TOKEN\_ID environment variable.
|
|
92
|
+
|
|
93
|
+
**tokenSecret** (`string`): Modal token secret. Falls back to MODAL\_TOKEN\_SECRET environment variable.
|
|
94
|
+
|
|
95
|
+
**instructions** (`string | function`): Custom instructions returned by getInstructions(). Pass a string to fully replace the default, or a function to extend it.
|
|
96
|
+
|
|
97
|
+
**onStart** (`function`): Lifecycle hook called after the sandbox reaches running status.
|
|
98
|
+
|
|
99
|
+
**onStop** (`function`): Lifecycle hook called before the sandbox stops.
|
|
100
|
+
|
|
101
|
+
**onDestroy** (`function`): Lifecycle hook called before the sandbox is destroyed.
|
|
102
|
+
|
|
103
|
+
## Properties
|
|
104
|
+
|
|
105
|
+
**id** (`string`): Sandbox instance identifier.
|
|
106
|
+
|
|
107
|
+
**name** (`string`): Provider name ('ModalSandbox')
|
|
108
|
+
|
|
109
|
+
**provider** (`string`): Provider identifier ('modal')
|
|
110
|
+
|
|
111
|
+
**status** (`ProviderStatus`): 'pending' | 'starting' | 'running' | 'stopping' | 'stopped' | 'destroying' | 'destroyed' | 'error'
|
|
112
|
+
|
|
113
|
+
**modal** (`Sandbox`): The underlying Modal Sandbox instance. Throws SandboxNotReadyError if the sandbox has not been started.
|
|
114
|
+
|
|
115
|
+
**processes** (`ModalProcessManager`): Background process manager. See \[SandboxProcessManager reference]\(/reference/workspace/process-manager).
|
|
116
|
+
|
|
117
|
+
## Sandbox lifecycle
|
|
118
|
+
|
|
119
|
+
- **`_start()`**: Attempts to reconnect to an existing running sandbox. If none is found, creates a sandbox from the latest snapshot (if available from a previous `_stop()`), or from the baseImage.
|
|
120
|
+
- **`_stop()`**: Snapshots the filesystem, then terminates the sandbox. Snapshot is kept in memory on the same instance for future starts.
|
|
121
|
+
- **`_destroy()`**: Terminates the sandbox and discards any snapshot.
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
const sandbox = new ModalSandbox({
|
|
125
|
+
id: 'dev-sandbox',
|
|
126
|
+
baseImage: 'ubuntu:22.04',
|
|
127
|
+
timeoutMs: 300_000,
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
await sandbox._start()
|
|
131
|
+
await sandbox.processes.spawn('npm install')
|
|
132
|
+
await sandbox._stop()
|
|
133
|
+
await sandbox._start()
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Background processes
|
|
137
|
+
|
|
138
|
+
`ModalSandbox` includes a built-in process manager for spawning and managing background processes. Each `spawn()` call creates a new `ContainerProcess` via the Modal SDK's `Sandbox.exec()` API.
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const sandbox = new ModalSandbox({ id: 'dev-sandbox' })
|
|
142
|
+
await sandbox._start()
|
|
143
|
+
|
|
144
|
+
// Spawn a background process
|
|
145
|
+
const handle = await sandbox.processes.spawn('node script.js', {
|
|
146
|
+
env: { PORT: '3000' },
|
|
147
|
+
onStdout: data => console.log(data),
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
// Wait for the process to complete
|
|
151
|
+
const result = await handle.wait()
|
|
152
|
+
console.log(result.exitCode)
|
|
153
|
+
|
|
154
|
+
// Kill the process
|
|
155
|
+
await handle.kill()
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
> **Note:** `sendStdin()` is not supported — the Modal JS SDK does not expose stdin on `Sandbox.exec()`.
|
|
159
|
+
|
|
160
|
+
See [`SandboxProcessManager` reference](https://mastra.ai/reference/workspace/process-manager) for the full API.
|
|
161
|
+
|
|
162
|
+
## Related
|
|
163
|
+
|
|
164
|
+
- [SandboxProcessManager reference](https://mastra.ai/reference/workspace/process-manager)
|
|
165
|
+
- [WorkspaceSandbox interface](https://mastra.ai/reference/workspace/sandbox)
|
|
166
|
+
- [E2BSandbox reference](https://mastra.ai/reference/workspace/e2b-sandbox)
|
|
167
|
+
- [DaytonaSandbox reference](https://mastra.ai/reference/workspace/daytona-sandbox)
|
|
168
|
+
- [Workspace overview](https://mastra.ai/docs/workspace/overview)
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Abstract base class for managing background processes in sandboxes. Provides methods to spawn processes, list them, get handles by PID, and kill them.
|
|
6
6
|
|
|
7
|
-
[`BlaxelSandbox`](https://mastra.ai/reference/workspace/blaxel-sandbox), [`DaytonaSandbox`](https://mastra.ai/reference/workspace/daytona-sandbox), [`E2BSandbox`](https://mastra.ai/reference/workspace/e2b-sandbox), and [`LocalSandbox`](https://mastra.ai/reference/workspace/local-sandbox) all include built-in process managers. You don't need to instantiate this class directly unless you're building a custom sandbox provider.
|
|
7
|
+
[`BlaxelSandbox`](https://mastra.ai/reference/workspace/blaxel-sandbox), [`DaytonaSandbox`](https://mastra.ai/reference/workspace/daytona-sandbox), [`E2BSandbox`](https://mastra.ai/reference/workspace/e2b-sandbox), [`ModalSandbox`](https://mastra.ai/reference/workspace/modal-sandbox), and [`LocalSandbox`](https://mastra.ai/reference/workspace/local-sandbox) all include built-in process managers. You don't need to instantiate this class directly unless you're building a custom sandbox provider.
|
|
8
8
|
|
|
9
9
|
## Usage example
|
|
10
10
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# S3Filesystem
|
|
2
2
|
|
|
3
|
-
Stores files in Amazon S3 or S3-compatible storage services like Cloudflare R2, MinIO,
|
|
3
|
+
Stores files in Amazon S3 or S3-compatible storage services like Cloudflare R2, MinIO, DigitalOcean Spaces, and Tigris.
|
|
4
4
|
|
|
5
5
|
> **Info:** For interface details, see [WorkspaceFilesystem Interface](https://mastra.ai/reference/workspace/filesystem).
|
|
6
6
|
|
|
@@ -55,6 +55,61 @@ const agent = new Agent({
|
|
|
55
55
|
})
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
+
### AWS credential provider chain
|
|
59
|
+
|
|
60
|
+
When no credentials are provided, `S3Filesystem` uses the AWS SDK default credential provider chain. This discovers credentials automatically from environment variables, `~/.aws` config files, ECS container credentials, EC2 instance profiles, and other standard sources.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { S3Filesystem } from '@mastra/s3'
|
|
64
|
+
|
|
65
|
+
// SDK discovers credentials from the environment automatically
|
|
66
|
+
const filesystem = new S3Filesystem({
|
|
67
|
+
bucket: 'my-bucket',
|
|
68
|
+
region: 'us-east-1',
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Pass a credential provider function for auto-refreshing credentials. This is useful for deployments on ECS, Lambda, or when using SSO/AssumeRole where temporary credentials expire and need to be refreshed.
|
|
73
|
+
|
|
74
|
+
Install the AWS SDK credential providers package when calling `fromNodeProviderChain()` directly:
|
|
75
|
+
|
|
76
|
+
**npm**:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm install @aws-sdk/credential-providers
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**pnpm**:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pnpm add @aws-sdk/credential-providers
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Yarn**:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
yarn add @aws-sdk/credential-providers
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Bun**:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
bun add @aws-sdk/credential-providers
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { S3Filesystem } from '@mastra/s3'
|
|
102
|
+
import { fromNodeProviderChain } from '@aws-sdk/credential-providers'
|
|
103
|
+
|
|
104
|
+
const filesystem = new S3Filesystem({
|
|
105
|
+
bucket: 'my-bucket',
|
|
106
|
+
region: 'us-east-1',
|
|
107
|
+
credentials: fromNodeProviderChain(),
|
|
108
|
+
})
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Provider functions only apply to `S3Filesystem` API calls. When mounting the filesystem into an E2B sandbox, mount configuration only supports static `accessKeyId`, `secretAccessKey`, and `sessionToken` values, so credential refresh must be handled outside the mount.
|
|
112
|
+
|
|
58
113
|
### Cloudflare R2
|
|
59
114
|
|
|
60
115
|
```typescript
|
|
@@ -83,19 +138,38 @@ const filesystem = new S3Filesystem({
|
|
|
83
138
|
})
|
|
84
139
|
```
|
|
85
140
|
|
|
141
|
+
### Tigris
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import { S3Filesystem } from '@mastra/s3'
|
|
145
|
+
|
|
146
|
+
const filesystem = new S3Filesystem({
|
|
147
|
+
bucket: 'my-bucket',
|
|
148
|
+
region: 'auto',
|
|
149
|
+
endpoint: 'https://t3.storage.dev',
|
|
150
|
+
accessKeyId: process.env.TIGRIS_ACCESS_KEY_ID,
|
|
151
|
+
secretAccessKey: process.env.TIGRIS_SECRET_ACCESS_KEY,
|
|
152
|
+
forcePathStyle: false,
|
|
153
|
+
})
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Tigris uses virtual-hosted-style addressing, so `forcePathStyle` must be set to `false` (the default is `true` when a custom endpoint is provided). Create credentials from the [Tigris Dashboard](https://console.tigris.dev/) — access keys are prefixed `tid_` and secrets `tsec_`.
|
|
157
|
+
|
|
86
158
|
## Constructor parameters
|
|
87
159
|
|
|
88
160
|
**bucket** (`string`): S3 bucket name
|
|
89
161
|
|
|
90
162
|
**region** (`string`): AWS region (use 'auto' for R2)
|
|
91
163
|
|
|
92
|
-
**
|
|
164
|
+
**credentials** (`AwsCredentialIdentity | AwsCredentialIdentityProvider`): AWS credentials or credential provider function. Accepts static credentials or a provider that auto-refreshes (e.g. \`fromNodeProviderChain()\` from \`@aws-sdk/credential-providers\`). Takes precedence over \`accessKeyId\`/\`secretAccessKey\`/\`sessionToken\`. When all credential options are omitted, the SDK default credential provider chain is used.
|
|
165
|
+
|
|
166
|
+
**accessKeyId** (`string`): AWS access key ID. When omitted along with \`secretAccessKey\` and \`credentials\`, the SDK default credential provider chain is used.
|
|
93
167
|
|
|
94
|
-
**secretAccessKey** (`string`): AWS secret access key.
|
|
168
|
+
**secretAccessKey** (`string`): AWS secret access key. When omitted along with \`accessKeyId\` and \`credentials\`, the SDK default credential provider chain is used.
|
|
95
169
|
|
|
96
|
-
**sessionToken** (`string`): AWS session token for temporary credentials.
|
|
170
|
+
**sessionToken** (`string`): AWS session token for static temporary credentials. Use with \`accessKeyId\`/\`secretAccessKey\` only when passing a complete temporary credential set manually. For auto-refreshing SSO, AssumeRole, or container credentials, use the \`credentials\` provider parameter or the SDK default credential provider chain.
|
|
97
171
|
|
|
98
|
-
**endpoint** (`string`): Custom endpoint URL for S3-compatible storage (R2, MinIO, etc.)
|
|
172
|
+
**endpoint** (`string`): Custom endpoint URL for S3-compatible storage (R2, MinIO, Tigris, etc.)
|
|
99
173
|
|
|
100
174
|
**forcePathStyle** (`boolean`): Force path-style URLs instead of virtual-hosted-style. Required for some S3-compatible services like MinIO. Defaults to true when a custom endpoint is provided. (Default: `true (when endpoint is set)`)
|
|
101
175
|
|
|
@@ -193,5 +267,6 @@ See [E2BSandbox reference](https://mastra.ai/reference/workspace/e2b-sandbox) fo
|
|
|
193
267
|
|
|
194
268
|
- [WorkspaceFilesystem interface](https://mastra.ai/reference/workspace/filesystem)
|
|
195
269
|
- [GCSFilesystem reference](https://mastra.ai/reference/workspace/gcs-filesystem)
|
|
270
|
+
- [AzureBlobFilesystem reference](https://mastra.ai/reference/workspace/azure-blob-filesystem)
|
|
196
271
|
- [E2BSandbox reference](https://mastra.ai/reference/workspace/e2b-sandbox)
|
|
197
272
|
- [Workspace overview](https://mastra.ai/docs/workspace/overview)
|