@mastra/mcp-docs-server 1.2.8-alpha.9 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/.docs/docs/agent-builder/integrations.md +1 -3
  2. package/.docs/docs/agent-builder/overview.md +2 -0
  3. package/.docs/docs/agents/overview.md +17 -13
  4. package/.docs/docs/agents/skills.md +1 -3
  5. package/.docs/docs/agents/structured-output.md +2 -0
  6. package/.docs/docs/agents/using-tools.md +66 -49
  7. package/.docs/docs/browser/agent-browser.md +1 -0
  8. package/.docs/docs/browser/firecrawl.md +129 -0
  9. package/.docs/docs/browser/overview.md +16 -2
  10. package/.docs/docs/capabilities/channels/slack.md +111 -1
  11. package/.docs/docs/deployment/mastra-server.md +35 -0
  12. package/.docs/docs/deployment/monorepo.md +2 -0
  13. package/.docs/docs/deployment/overview.md +6 -0
  14. package/.docs/docs/deployment/sandbox.md +277 -0
  15. package/.docs/docs/editor/overview.md +2 -6
  16. package/.docs/docs/editor/tools.md +2 -6
  17. package/.docs/docs/evals/running-in-ci.md +3 -9
  18. package/.docs/docs/getting-started/build-with-ai.md +2 -6
  19. package/.docs/docs/getting-started/manual-install.md +1 -1
  20. package/.docs/docs/index.md +17 -13
  21. package/.docs/docs/long-running-agents/background-tasks.md +2 -2
  22. package/.docs/docs/long-running-agents/goals.md +3 -1
  23. package/.docs/docs/mastra-platform/database.md +12 -6
  24. package/.docs/docs/mastra-platform/deploy.md +14 -7
  25. package/.docs/docs/mastra-platform/environments.md +5 -4
  26. package/.docs/docs/mastra-platform/observability.md +4 -12
  27. package/.docs/docs/mastra-platform/overview.md +1 -1
  28. package/.docs/docs/mastra-platform/regions.md +73 -0
  29. package/.docs/docs/mastra-platform/workspace.md +111 -0
  30. package/.docs/docs/memory/observational-memory.md +77 -2
  31. package/.docs/docs/memory/overview.md +4 -0
  32. package/.docs/docs/observability/feedback.md +4 -0
  33. package/.docs/docs/observability/integrations/bridges/otel.md +1 -3
  34. package/.docs/docs/observability/integrations/exporters/otel.md +1 -3
  35. package/.docs/docs/server/auth/fga.md +40 -0
  36. package/.docs/docs/server/auth/simple-auth.md +1 -3
  37. package/.docs/docs/studio/overview.md +2 -0
  38. package/.docs/docs/workflows/control-flow.md +1 -3
  39. package/.docs/docs/workspace/filesystem.md +1 -0
  40. package/.docs/docs/workspace/sandbox.md +1 -0
  41. package/.docs/guides/getting-started/quickstart.md +40 -25
  42. package/.docs/guides/index.md +1 -1
  43. package/.docs/guides/migrations/vnext-to-standard-apis.md +1 -3
  44. package/.docs/models/environment-variables.md +2 -0
  45. package/.docs/models/gateways/netlify.md +3 -6
  46. package/.docs/models/gateways/openrouter.md +343 -346
  47. package/.docs/models/gateways/vercel.md +6 -5
  48. package/.docs/models/index.md +1 -1
  49. package/.docs/models/providers/aki-io.md +78 -0
  50. package/.docs/models/providers/alibaba-token-plan-cn.md +22 -21
  51. package/.docs/models/providers/alibaba-token-plan.md +22 -21
  52. package/.docs/models/providers/ambient.md +12 -10
  53. package/.docs/models/providers/baseten.md +2 -1
  54. package/.docs/models/providers/cline-pass.md +82 -0
  55. package/.docs/models/providers/cortecs.md +2 -1
  56. package/.docs/models/providers/crossmodel.md +2 -1
  57. package/.docs/models/providers/deepinfra.md +4 -7
  58. package/.docs/models/providers/deepseek.md +3 -1
  59. package/.docs/models/providers/empiriolabs.md +2 -1
  60. package/.docs/models/providers/google.md +4 -2
  61. package/.docs/models/providers/huggingface.md +2 -1
  62. package/.docs/models/providers/inferx.md +3 -3
  63. package/.docs/models/providers/kenari.md +44 -29
  64. package/.docs/models/providers/kimi-for-coding.md +6 -9
  65. package/.docs/models/providers/llmgateway.md +4 -1
  66. package/.docs/models/providers/moonshotai-cn.md +1 -1
  67. package/.docs/models/providers/moonshotai.md +1 -1
  68. package/.docs/models/providers/nebius.md +3 -1
  69. package/.docs/models/providers/novita-ai.md +3 -1
  70. package/.docs/models/providers/opencode-go.md +4 -3
  71. package/.docs/models/providers/opencode.md +4 -2
  72. package/.docs/models/providers/poolside.md +2 -2
  73. package/.docs/models/providers/togetherai.md +2 -6
  74. package/.docs/models/providers/wandb.md +2 -1
  75. package/.docs/models/providers/zenmux.md +3 -1
  76. package/.docs/models/providers.md +2 -0
  77. package/.docs/reference/agent-controller/session.md +13 -0
  78. package/.docs/reference/agents/agent.md +13 -1
  79. package/.docs/reference/agents/generate.md +18 -0
  80. package/.docs/reference/browser/firecrawl-browser.md +71 -0
  81. package/.docs/reference/cli/create-mastra.md +118 -43
  82. package/.docs/reference/cli/mastra.md +59 -5
  83. package/.docs/reference/code-sdk/mount-agent-controller.md +4 -4
  84. package/.docs/reference/core/getMCPServer.md +1 -3
  85. package/.docs/reference/core/getMCPServerById.md +1 -3
  86. package/.docs/reference/core/getWorkflow.md +1 -3
  87. package/.docs/reference/core/listMCPServers.md +2 -6
  88. package/.docs/reference/datasets/addItem.md +1 -3
  89. package/.docs/reference/datasets/addItems.md +1 -3
  90. package/.docs/reference/datasets/compareExperiments.md +1 -3
  91. package/.docs/reference/datasets/create.md +1 -3
  92. package/.docs/reference/datasets/dataset.md +2 -6
  93. package/.docs/reference/datasets/datasets-manager.md +5 -15
  94. package/.docs/reference/datasets/delete.md +1 -3
  95. package/.docs/reference/datasets/deleteExperiment.md +1 -3
  96. package/.docs/reference/datasets/deleteItem.md +1 -3
  97. package/.docs/reference/datasets/deleteItems.md +1 -3
  98. package/.docs/reference/datasets/get.md +1 -3
  99. package/.docs/reference/datasets/getDetails.md +1 -3
  100. package/.docs/reference/datasets/getExperiment.md +1 -3
  101. package/.docs/reference/datasets/getItem.md +1 -3
  102. package/.docs/reference/datasets/getItemHistory.md +1 -3
  103. package/.docs/reference/datasets/list.md +1 -3
  104. package/.docs/reference/datasets/listExperimentResults.md +1 -3
  105. package/.docs/reference/datasets/listExperiments.md +1 -3
  106. package/.docs/reference/datasets/listItems.md +1 -3
  107. package/.docs/reference/datasets/listVersions.md +1 -3
  108. package/.docs/reference/datasets/startExperiment.md +1 -3
  109. package/.docs/reference/datasets/startExperimentAsync.md +1 -3
  110. package/.docs/reference/datasets/update.md +1 -3
  111. package/.docs/reference/datasets/updateItem.md +1 -3
  112. package/.docs/reference/editor/mastra-editor.md +1 -3
  113. package/.docs/reference/evals/context-recall.md +205 -0
  114. package/.docs/reference/evals/create-scorer.md +3 -9
  115. package/.docs/reference/evals/mastra-scorer.md +1 -3
  116. package/.docs/reference/file-based-agents/tools.md +7 -6
  117. package/.docs/reference/index.md +5 -0
  118. package/.docs/reference/memory/observational-memory.md +21 -0
  119. package/.docs/reference/observability/tracing/exporters/posthog.md +39 -1
  120. package/.docs/reference/observability/tracing/processors/sensitive-data-filter.md +1 -3
  121. package/.docs/reference/processors/token-limiter-processor.md +1 -3
  122. package/.docs/reference/rag/database-config.md +12 -0
  123. package/.docs/reference/streaming/agents/stream.md +2 -0
  124. package/.docs/reference/templates/overview.md +6 -32
  125. package/.docs/reference/tools/create-tool.md +78 -52
  126. package/.docs/reference/tools/mcp-client.md +8 -24
  127. package/.docs/reference/tools/mcp-server.md +143 -44
  128. package/.docs/reference/tools/tavily.md +1 -1
  129. package/.docs/reference/tools/vector-query-tool.md +22 -0
  130. package/.docs/reference/vectors/mongodb.md +2 -0
  131. package/.docs/reference/vectors/turbopuffer.md +4 -0
  132. package/.docs/reference/voice/mistral.md +127 -0
  133. package/.docs/reference/workspace/daytona-sandbox.md +2 -6
  134. package/.docs/reference/workspace/platform-filesystem.md +182 -0
  135. package/.docs/reference/workspace/platform-sandbox.md +200 -0
  136. package/.docs/reference/workspace/railway-sandbox.md +37 -1
  137. package/CHANGELOG.md +71 -0
  138. package/dist/{chunk-GLPCVXXO.js → chunk-HGADBLKG.js} +2 -2
  139. package/dist/{chunk-GLPCVXXO.js.map → chunk-HGADBLKG.js.map} +1 -1
  140. package/dist/index.js +1 -1
  141. package/dist/stdio.js +1 -1
  142. package/dist/tools/docs.d.ts.map +1 -1
  143. package/package.json +8 -8
@@ -0,0 +1,127 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Mistral
4
+
5
+ The MistralVoice class provides text-to-speech and speech-to-text capabilities using Mistral's Voxtral audio models. It supports buffered and streaming TTS, batch transcription with diarization, and voice cloning via reference audio.
6
+
7
+ ## Usage example
8
+
9
+ ```typescript
10
+ import { MistralVoice } from '@mastra/voice-mistral'
11
+
12
+ const voice = new MistralVoice()
13
+
14
+ // Text-to-speech
15
+ const audioStream = await voice.speak('Hello, how can I help you?', {
16
+ responseFormat: 'mp3',
17
+ })
18
+
19
+ // Speech-to-text
20
+ const text = await voice.listen(audioStream, {
21
+ language: 'en',
22
+ })
23
+
24
+ // List available voices
25
+ const speakers = await voice.getSpeakers()
26
+ ```
27
+
28
+ ```typescript
29
+ import { MistralVoice } from '@mastra/voice-mistral'
30
+
31
+ // Initialize with specific configuration
32
+ const voice = new MistralVoice({
33
+ speechModel: {
34
+ name: 'voxtral-mini-tts-2603',
35
+ apiKey: 'your-mistral-api-key',
36
+ },
37
+ listeningModel: {
38
+ name: 'voxtral-mini-latest',
39
+ apiKey: 'your-mistral-api-key',
40
+ },
41
+ speaker: 'en_paul_neutral',
42
+ })
43
+ ```
44
+
45
+ ## Constructor parameters
46
+
47
+ **speechModel** (`MistralModelConfig`): Configuration for text-to-speech synthesis. (Default: `{ name: 'voxtral-mini-tts-2603' }`)
48
+
49
+ **speechModel.name** (`string`): Model ID for speech synthesis.
50
+
51
+ **speechModel.apiKey** (`string`): Mistral API key. Falls back to MISTRAL\_API\_KEY environment variable.
52
+
53
+ **listeningModel** (`MistralModelConfig`): Configuration for speech-to-text recognition. (Default: `{ name: 'voxtral-mini-latest' }`)
54
+
55
+ **listeningModel.name** (`string`): Model ID for transcription. Use 'voxtral-mini-2507' for a pinned version.
56
+
57
+ **listeningModel.apiKey** (`string`): Mistral API key. Falls back to MISTRAL\_API\_KEY environment variable.
58
+
59
+ **speaker** (`string`): Default voice ID for speech synthesis. Retrieve available IDs from getSpeakers(). (Default: `'en_paul_neutral'`)
60
+
61
+ ## Methods
62
+
63
+ ### `speak(input, options?)`
64
+
65
+ Converts text to speech using Mistral's Voxtral TTS model. Supports both buffered and streaming output.
66
+
67
+ **input** (`string | NodeJS.ReadableStream`): Text or text stream to convert to speech.
68
+
69
+ **options** (`MistralSpeakOptions`): Configuration options.
70
+
71
+ **options.speaker** (`string`): Voice ID to use. Overrides the constructor default.
72
+
73
+ **options.responseFormat** (`'pcm' | 'wav' | 'mp3' | 'flac' | 'opus'`): Audio output format. Use 'pcm' for lowest latency streaming.
74
+
75
+ **options.refAudio** (`string`): Base64-encoded reference audio for one-off voice cloning (minimum 2-3 seconds).
76
+
77
+ **options.model** (`string`): Override the speech model for this call.
78
+
79
+ **options.stream** (`boolean`): Enable streaming TTS. Audio chunks are written to the stream as they arrive.
80
+
81
+ Returns: `Promise<NodeJS.ReadableStream>`
82
+
83
+ ### `listen(audioStream, options?)`
84
+
85
+ Transcribes audio using Mistral's Voxtral transcription model. Supports diarization, context biasing, and timestamp granularity.
86
+
87
+ **audioStream** (`NodeJS.ReadableStream`): Audio stream to transcribe.
88
+
89
+ **options** (`MistralListenOptions`): Configuration options.
90
+
91
+ **options.language** (`string`): Language code (e.g., 'en'). Improves accuracy when specified.
92
+
93
+ **options.diarize** (`boolean`): Enable speaker diarization.
94
+
95
+ **options.contextBias** (`string[]`): Words or phrases for vocabulary guidance.
96
+
97
+ **options.timestampGranularities** (`('segment' | 'word')[]`): Timestamp detail level for transcription segments.
98
+
99
+ **options.filetype** (`string`): Audio file extension hint for the input stream.
100
+
101
+ Returns: `Promise<string>`
102
+
103
+ ### `getSpeakers()`
104
+
105
+ Fetches available preset voices from the Mistral Voices API. Each entry contains:
106
+
107
+ **voiceId** (`string`): Unique identifier for the voice.
108
+
109
+ **name** (`string`): Display name of the voice.
110
+
111
+ **languages** (`string[]`): Languages supported by the voice.
112
+
113
+ **gender** (`string | null`): Gender of the voice.
114
+
115
+ ### `getListener()`
116
+
117
+ Returns `{ enabled: true }`.
118
+
119
+ ## Notes
120
+
121
+ - API keys can be provided via constructor options or the `MISTRAL_API_KEY` environment variable
122
+ - TTS supports 9 languages: English, French, Spanish, Portuguese, Italian, Dutch, German, Hindi, Arabic
123
+ - STT supports 13 languages: English, Chinese, Hindi, Spanish, Arabic, French, Portuguese, Russian, German, Japanese, Korean, Italian, Dutch
124
+ - TTS input text should be kept under 300 words per request for best results
125
+ - STT supports up to 3 hours of audio per request
126
+ - Voice cloning via `refAudio` requires a minimum of 2-3 seconds of reference audio
127
+ - `getSpeakers()` returns preset voices with UUID identifiers. The default `en_paul_neutral` is a named alias accepted by the TTS endpoint but not included in the list
@@ -440,12 +440,8 @@ Then use the snapshot name in your sandbox config:
440
440
  ```typescript
441
441
  const workspace = new Workspace({
442
442
  mounts: {
443
- '/s3-data': new S3Filesystem({
444
- /* ... */
445
- }),
446
- '/gcs-data': new GCSFilesystem({
447
- /* ... */
448
- }),
443
+ '/s3-data': new S3Filesystem({/* ... */}),
444
+ '/gcs-data': new GCSFilesystem({/* ... */}),
449
445
  },
450
446
  sandbox: new DaytonaSandbox({ snapshot: 'cloud-fs-mounting' }),
451
447
  })
@@ -0,0 +1,182 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # PlatformFilesystem
4
+
5
+ Stores files in a Mastra Platform workspace bucket. Each Mastra Platform environment can have one bucket, and `PlatformFilesystem` gives agents `read`, `write`, `list`, `delete`, and `move` operations against it.
6
+
7
+ Use `PlatformFilesystem` when your agent runs on a Mastra Platform deployment and you want the filesystem to be backed by the platform-provisioned bucket. For direct S3 access, see [`S3Filesystem`](https://mastra.ai/reference/workspace/s3-filesystem). For a local directory during development, see [`LocalFilesystem`](https://mastra.ai/reference/workspace/local-filesystem).
8
+
9
+ > **Info:** For interface details, see [WorkspaceFilesystem interface](https://mastra.ai/reference/workspace/filesystem).
10
+
11
+ ## Installation
12
+
13
+ **npm**:
14
+
15
+ ```bash
16
+ npm install @mastra/platform-workspace
17
+ ```
18
+
19
+ **pnpm**:
20
+
21
+ ```bash
22
+ pnpm add @mastra/platform-workspace
23
+ ```
24
+
25
+ **Yarn**:
26
+
27
+ ```bash
28
+ yarn add @mastra/platform-workspace
29
+ ```
30
+
31
+ **Bun**:
32
+
33
+ ```bash
34
+ bun add @mastra/platform-workspace
35
+ ```
36
+
37
+ Configure the platform credentials. The access token, project ID, and bucket name fall back to environment variables, so a Mastra Platform deployment can pass zero constructor options.
38
+
39
+ **.env file**:
40
+
41
+ ```bash
42
+ MASTRA_PLATFORM_SECRET_KEY=your-platform-secret-key
43
+ MASTRA_PROJECT_ID=your-project-id
44
+ MASTRA_PLATFORM_BUCKET_NAME=your-bucket-name
45
+ ```
46
+
47
+ **Constructor**:
48
+
49
+ ```typescript
50
+ new PlatformFilesystem({
51
+ accessToken: 'your-platform-access-token',
52
+ projectId: 'your-project-id',
53
+ bucketName: 'your-bucket-name',
54
+ })
55
+ ```
56
+
57
+ On a Mastra Platform deployment these variables are injected automatically, so the constructor can be called with no options.
58
+
59
+ ## Usage
60
+
61
+ Add a `PlatformFilesystem` to a workspace and assign it to an agent:
62
+
63
+ ```typescript
64
+ import { Agent } from '@mastra/core/agent'
65
+ import { Workspace } from '@mastra/core/workspace'
66
+ import { PlatformFilesystem } from '@mastra/platform-workspace'
67
+
68
+ const workspace = new Workspace({
69
+ filesystem: new PlatformFilesystem({
70
+ // accessToken, projectId, bucketName all fall back to env vars
71
+ }),
72
+ })
73
+
74
+ const agent = new Agent({
75
+ id: 'file-agent',
76
+ name: 'File Agent',
77
+ instructions: 'You are a research assistant that reads and writes reports.',
78
+ model: 'anthropic/claude-sonnet-4-6',
79
+ workspace,
80
+ })
81
+ ```
82
+
83
+ ### Reading and writing files
84
+
85
+ Object keys are percent-encoded per segment, so filenames with `?`, `#`, `%`, `&`, `+`, or spaces are preserved end-to-end:
86
+
87
+ ```typescript
88
+ const fs = new PlatformFilesystem()
89
+
90
+ await fs.writeFile('/analyses/repo.md', markdown)
91
+ const content = await fs.readFile('/analyses/repo.md')
92
+ const entries = await fs.readdir('/analyses')
93
+ await fs.moveFile('/analyses/repo.md', '/analyses/repo-final.md')
94
+ ```
95
+
96
+ ### Read-only mode
97
+
98
+ Pass `readOnly: true` to mount the bucket read-only. Any mutating call throws `WorkspaceReadOnlyError`:
99
+
100
+ ```typescript
101
+ const fs = new PlatformFilesystem({ readOnly: true })
102
+
103
+ await fs.readFile('/analyses/repo.md') // ok
104
+ await fs.writeFile('/analyses/repo.md', 'x') // throws WorkspaceReadOnlyError
105
+ ```
106
+
107
+ ### Overwrite semantics
108
+
109
+ `writeFile` supports `overwrite: false` and throws `FileExistsError` when the destination already exists.
110
+
111
+ `copyFile` and `moveFile` always overwrite the destination. Passing `overwrite: false` to either method throws an error rather than silently overwriting.
112
+
113
+ ### Appending files
114
+
115
+ `appendFile` is a read-modify-write and is not atomic. Concurrent appends to the same path can overwrite each other. For concurrent writers, use `writeFile` with distinct keys.
116
+
117
+ ## Constructor parameters
118
+
119
+ **accessToken** (`string`): Platform secret key. Falls back to the MASTRA\_PLATFORM\_SECRET\_KEY environment variable (MASTRA\_PLATFORM\_ACCESS\_TOKEN is a deprecated fallback).
120
+
121
+ **projectId** (`string`): Platform project ID. Falls back to the MASTRA\_PROJECT\_ID environment variable.
122
+
123
+ **bucketName** (`string`): Platform bucket name to store files in. Falls back to the MASTRA\_PLATFORM\_BUCKET\_NAME environment variable.
124
+
125
+ **readOnly** (`boolean`): When true, all mutating calls throw WorkspaceReadOnlyError. (Default: `false`)
126
+
127
+ **displayName** (`string`): Human-readable name shown in workspace UIs.
128
+
129
+ **description** (`string`): Short description shown in workspace UIs.
130
+
131
+ **icon** (`FilesystemIcon`): Icon shown in workspace UIs.
132
+
133
+ **instructions** (`string | ((opts: { defaultInstructions: string; requestContext?: RequestContext }) => string)`): Custom instructions returned by getInstructions(). A string fully replaces the defaults; a function receives the defaults and can extend or customize them per-request.
134
+
135
+ **id** (`string`): Unique identifier for this filesystem instance. (Default: `Auto-generated`)
136
+
137
+ **fetch** (`typeof fetch`): Custom fetch implementation, mainly for testing.
138
+
139
+ ## Properties
140
+
141
+ **id** (`string`): Filesystem instance identifier.
142
+
143
+ **name** (`string`): Provider name ('PlatformFilesystem').
144
+
145
+ **provider** (`string`): Provider identifier ('platform').
146
+
147
+ **readOnly** (`boolean | undefined`): Whether the filesystem was mounted read-only.
148
+
149
+ ## Errors
150
+
151
+ Filesystem-specific errors match the standard workspace error types:
152
+
153
+ - `FileNotFoundError`: The path does not exist. Thrown by `readFile`, `stat`, and `deleteFile` (unless `force: true` is set).
154
+ - `FileExistsError`: `writeFile` was called with `overwrite: false` and the destination already exists.
155
+ - `WorkspaceReadOnlyError`: A mutating call was made on a read-only filesystem.
156
+
157
+ Other Platform API failures raise `PlatformApiError`. Structured `{ error: { message, type } }` responses are parsed into `.code` (machine-readable kind) and `.proxyMessage` (human string):
158
+
159
+ ```typescript
160
+ import { FileNotFoundError, PlatformApiError } from '@mastra/platform-workspace'
161
+
162
+ try {
163
+ await fs.readFile('/missing.txt')
164
+ } catch (err) {
165
+ if (err instanceof FileNotFoundError) {
166
+ // handle missing file
167
+ } else if (err instanceof PlatformApiError) {
168
+ if (err.code === 'authentication_error') {
169
+ // refresh token
170
+ }
171
+ console.error(err.status, err.code, err.proxyMessage)
172
+ }
173
+ }
174
+ ```
175
+
176
+ `code` and `proxyMessage` are `undefined` when the response body is not JSON, for example an HTML 502 from a load balancer.
177
+
178
+ ## Related
179
+
180
+ - [PlatformSandbox reference](https://mastra.ai/reference/workspace/platform-sandbox)
181
+ - [S3Filesystem reference](https://mastra.ai/reference/workspace/s3-filesystem)
182
+ - [WorkspaceFilesystem interface](https://mastra.ai/reference/workspace/filesystem)
@@ -0,0 +1,200 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # PlatformSandbox
4
+
5
+ Executes commands inside a Mastra Platform sandbox tied to a Platform environment. Sandboxes boot from a pre-built recipe checkpoint with Python 3, Node 22, TypeScript, tsx, and common build tooling already installed.
6
+
7
+ Use `PlatformSandbox` when your agent runs on a Mastra Platform deployment and you want the sandbox to be provisioned and managed by the platform. For self-hosted Railway sandboxes, see [`RailwaySandbox`](https://mastra.ai/reference/workspace/railway-sandbox). For a local sandbox during development, see [`LocalSandbox`](https://mastra.ai/reference/workspace/local-sandbox).
8
+
9
+ > **Info:** For interface details, see [WorkspaceSandbox interface](https://mastra.ai/reference/workspace/sandbox).
10
+
11
+ ## Installation
12
+
13
+ **npm**:
14
+
15
+ ```bash
16
+ npm install @mastra/platform-workspace
17
+ ```
18
+
19
+ **pnpm**:
20
+
21
+ ```bash
22
+ pnpm add @mastra/platform-workspace
23
+ ```
24
+
25
+ **Yarn**:
26
+
27
+ ```bash
28
+ yarn add @mastra/platform-workspace
29
+ ```
30
+
31
+ **Bun**:
32
+
33
+ ```bash
34
+ bun add @mastra/platform-workspace
35
+ ```
36
+
37
+ Configure the platform credentials. The access token, project ID, and environment ID fall back to environment variables, so a Mastra Platform deployment can pass zero constructor options.
38
+
39
+ **.env file**:
40
+
41
+ ```bash
42
+ MASTRA_PLATFORM_SECRET_KEY=your-platform-secret-key
43
+ MASTRA_PROJECT_ID=your-project-id
44
+ MASTRA_ENVIRONMENT_ID=your-environment-id
45
+ ```
46
+
47
+ **Constructor**:
48
+
49
+ ```typescript
50
+ new PlatformSandbox({
51
+ accessToken: 'your-platform-access-token',
52
+ projectId: 'your-project-id',
53
+ environmentId: 'your-environment-id',
54
+ })
55
+ ```
56
+
57
+ On a Mastra Platform deployment these variables are injected automatically, so the constructor can be called with no options.
58
+
59
+ ## Usage
60
+
61
+ Add a `PlatformSandbox` to a workspace and assign it to an agent:
62
+
63
+ ```typescript
64
+ import { Agent } from '@mastra/core/agent'
65
+ import { Workspace } from '@mastra/core/workspace'
66
+ import { PlatformSandbox } from '@mastra/platform-workspace'
67
+
68
+ const workspace = new Workspace({
69
+ sandbox: new PlatformSandbox({
70
+ // accessToken, projectId, environmentId all fall back to env vars
71
+ idleTimeoutMinutes: 30,
72
+ }),
73
+ })
74
+
75
+ const agent = new Agent({
76
+ id: 'code-agent',
77
+ name: 'Code Agent',
78
+ instructions: 'You are a coding assistant working in this workspace.',
79
+ model: 'anthropic/claude-sonnet-4-6',
80
+ workspace,
81
+ })
82
+
83
+ const response = await agent.generate(
84
+ 'Print "Hello, world!" and show the current working directory.',
85
+ )
86
+
87
+ console.log(response.text)
88
+ ```
89
+
90
+ ### Private networking
91
+
92
+ Set `networkIsolation` to `PRIVATE` to join the environment's private network and reach other services running in the same Mastra Platform environment:
93
+
94
+ ```typescript
95
+ const workspace = new Workspace({
96
+ sandbox: new PlatformSandbox({
97
+ networkIsolation: 'PRIVATE',
98
+ }),
99
+ })
100
+ ```
101
+
102
+ The default `ISOLATED` mode allows outbound internet access only, with no private network connectivity.
103
+
104
+ ### Reattaching to a running sandbox
105
+
106
+ Pass an existing `sandboxId` to reattach to a live sandbox instead of creating a new one. This is useful for stateful agents that resume between requests:
107
+
108
+ ```typescript
109
+ const sandbox = new PlatformSandbox({
110
+ sandboxId: 'sbx_abc123',
111
+ })
112
+ await sandbox.start()
113
+
114
+ const result = await sandbox.executeCommand('cat', ['/workspace/state.json'])
115
+ ```
116
+
117
+ When `sandboxId` is set, `environmentId` is not required because the sandbox already exists.
118
+
119
+ ### Executing commands
120
+
121
+ `executeCommand` runs a command on the remote sandbox and returns its output. Pass `args` to have arguments safely shell-quoted:
122
+
123
+ ```typescript
124
+ const result = await sandbox.executeCommand('python', ['analyze.py'], {
125
+ timeout: 30_000,
126
+ cwd: '/workspace',
127
+ env: { INPUT: 'repo' },
128
+ })
129
+
130
+ console.log(result.stdout)
131
+ console.log(result.exitCode)
132
+ ```
133
+
134
+ > **Warning:** The `command` argument is a shell string and is concatenated verbatim into the remote shell. This lets you use pipes, redirects, and chaining (`ls -la | grep foo`) but means untrusted input must be passed through `args` (safely quoted) or shell-quoted by the caller. Untrusted `command` values allow arbitrary shell execution on the sandbox.
135
+
136
+ ## Constructor parameters
137
+
138
+ **accessToken** (`string`): Platform secret key. Falls back to the MASTRA\_PLATFORM\_SECRET\_KEY environment variable (MASTRA\_PLATFORM\_ACCESS\_TOKEN is a deprecated fallback).
139
+
140
+ **projectId** (`string`): Platform project ID. Falls back to the MASTRA\_PROJECT\_ID environment variable.
141
+
142
+ **environmentId** (`string`): Platform environment ID the sandbox belongs to. Falls back to the MASTRA\_ENVIRONMENT\_ID environment variable. Required unless sandboxId is passed.
143
+
144
+ **sandboxId** (`string`): Existing sandbox ID to reattach to instead of creating a new sandbox. When set, environmentId is not required.
145
+
146
+ **idleTimeoutMinutes** (`number`): How long the sandbox stays alive with no activity before the platform destroys it.
147
+
148
+ **networkIsolation** (`'ISOLATED' | 'PRIVATE'`): Network mode. 'ISOLATED' (default) allows outbound internet only. 'PRIVATE' joins the platform environment's private network.
149
+
150
+ **env** (`Record<string, string>`): Environment variables baked into the sandbox at creation time. Per-command environment variables can also be passed to executeCommand.
151
+
152
+ **timeout** (`number`): Default command execution timeout in milliseconds. Overridable per call via ExecuteCommandOptions.timeout.
153
+
154
+ **instructions** (`string | ((opts: { defaultInstructions: string; requestContext?: RequestContext }) => string)`): Custom instructions returned by getInstructions(). A string fully replaces the defaults; a function receives the defaults and can extend or customize them per-request.
155
+
156
+ **id** (`string`): Unique identifier for this sandbox instance. (Default: `Auto-generated`)
157
+
158
+ **fetch** (`typeof fetch`): Custom fetch implementation, mainly for testing.
159
+
160
+ ## Properties
161
+
162
+ **id** (`string`): Sandbox instance identifier.
163
+
164
+ **name** (`string`): Provider name ('PlatformSandbox').
165
+
166
+ **provider** (`string`): Provider identifier ('platform').
167
+
168
+ **status** (`ProviderStatus`): 'pending' | 'initializing' | 'ready' | 'starting' | 'running' | 'stopping' | 'stopped' | 'destroying' | 'destroyed' | 'error'.
169
+
170
+ **processes** (`PlatformProcessManager`): Background process manager. See SandboxProcessManager reference.
171
+
172
+ ## Errors
173
+
174
+ Platform API failures raise `PlatformApiError`. Structured `{ error: { message, type } }` responses are parsed into `.code` (machine-readable kind) and `.proxyMessage` (human string); the raw response body stays available on `.body`:
175
+
176
+ ```typescript
177
+ import { PlatformApiError } from '@mastra/platform-workspace'
178
+
179
+ try {
180
+ await sandbox.executeCommand('cat', ['/missing.txt'])
181
+ } catch (err) {
182
+ if (err instanceof PlatformApiError) {
183
+ if (err.code === 'not_found') {
184
+ // handle missing resource
185
+ } else if (err.code === 'authentication_error') {
186
+ // refresh token
187
+ }
188
+ console.error(err.status, err.code, err.proxyMessage)
189
+ }
190
+ }
191
+ ```
192
+
193
+ `code` and `proxyMessage` are `undefined` when the response body is not JSON, for example an HTML 502 from a load balancer.
194
+
195
+ ## Related
196
+
197
+ - [PlatformFilesystem reference](https://mastra.ai/reference/workspace/platform-filesystem)
198
+ - [RailwaySandbox reference](https://mastra.ai/reference/workspace/railway-sandbox)
199
+ - [WorkspaceSandbox interface](https://mastra.ai/reference/workspace/sandbox)
200
+ - [SandboxProcessManager reference](https://mastra.ai/reference/workspace/process-manager)
@@ -2,7 +2,7 @@
2
2
 
3
3
  # RailwaySandbox
4
4
 
5
- Executes commands in ephemeral, isolated [Railway](https://docs.railway.com/sandboxes) sandboxes. Each sandbox is an isolated Debian Linux VM provisioned on demand through the Railway TypeScript SDK. Supports command execution with streaming output, command timeouts, configurable idle timeout, `ISOLATED`/`PRIVATE` network isolation, custom base images via the Railway template builder, forking a running sandbox, and reattaching to an existing sandbox by ID. For interface details, see [WorkspaceSandbox interface](https://mastra.ai/reference/workspace/sandbox).
5
+ Executes commands in ephemeral, isolated [Railway](https://docs.railway.com/sandboxes) sandboxes. Each sandbox is an isolated Debian Linux VM provisioned on demand through the Railway TypeScript SDK. Supports command execution with streaming output, command timeouts, configurable idle timeout, `ISOLATED`/`PRIVATE` network isolation, custom base images via the Railway template builder, checkpoint-backed recovery, forking a running sandbox, and reattaching to an existing sandbox by ID. For interface details, see [WorkspaceSandbox interface](https://mastra.ai/reference/workspace/sandbox).
6
6
 
7
7
  ## Installation
8
8
 
@@ -128,6 +128,38 @@ console.log(result.stdout)
128
128
 
129
129
  The forked sandbox inherits the parent's credentials and defaults unless overridden via the `fork()` options.
130
130
 
131
+ ### Checkpoint recovery
132
+
133
+ Set `checkpointName` to preserve a sandbox filesystem across Railway sandbox replacement. On `start()`, `RailwaySandbox` first tries to create the sandbox from the named checkpoint. If the checkpoint is missing, it creates a sandbox from the configured template or default image, then captures the checkpoint.
134
+
135
+ ```typescript
136
+ const sandbox = new RailwaySandbox({
137
+ checkpointName: 'project-session-42',
138
+ idleTimeoutMinutes: 30,
139
+ })
140
+ ```
141
+
142
+ `RailwaySandbox` refreshes the checkpoint shortly before the idle timeout. Recovery restores the latest successful checkpoint. It doesn't restore running processes or filesystem writes made after the last checkpoint.
143
+
144
+ Use one stable checkpoint name for each independent filesystem. Do not share a checkpoint name across unrelated sessions or projects.
145
+
146
+ ### Derived sandbox checkpoints
147
+
148
+ Use `derive({ checkpointName })` when a configured `RailwaySandbox` acts as the template for a sandbox fleet:
149
+
150
+ ```typescript
151
+ const template = new RailwaySandbox({ idleTimeoutMinutes: 30 })
152
+
153
+ const sessionSandbox = template.derive({
154
+ id: 'session-42',
155
+ checkpointName: 'project-session-42',
156
+ })
157
+
158
+ await sessionSandbox.start()
159
+ ```
160
+
161
+ A derived sandbox uses the checkpoint passed to `derive()`. If no override is passed, it inherits the template sandbox's `checkpointName`.
162
+
131
163
  ### Streaming output
132
164
 
133
165
  Stream command output in real time via `onStdout` and `onStderr` callbacks:
@@ -162,6 +194,8 @@ const result = await sandbox.executeCommand('cat', ['/tmp/state.txt'])
162
194
 
163
195
  **sandboxId** (`string`): Reattach to an existing Railway sandbox by its Railway ID instead of creating a new one. When set, start() calls Sandbox.connect().
164
196
 
197
+ **checkpointName** (`string`): Named Railway checkpoint used to seed new sandboxes and preserve the filesystem before idle teardown. Use a unique stable name for each independent filesystem.
198
+
165
199
  **idleTimeoutMinutes** (`number`): How long the sandbox can sit idle (no exec interaction) before Railway destroys it automatically. The valid range and default depend on your Railway plan.
166
200
 
167
201
  **networkIsolation** (`'ISOLATED' | 'PRIVATE'`): Network access mode. 'ISOLATED' allows outbound internet only; 'PRIVATE' joins the environment's private network. (Default: `'ISOLATED'`)
@@ -192,6 +226,8 @@ const result = await sandbox.executeCommand('cat', ['/tmp/state.txt'])
192
226
 
193
227
  **fork** (`(options?) => Promise<RailwaySandbox>`): Clone this running sandbox into a new, independent RailwaySandbox. The returned sandbox is already started and reattached to the forked Railway sandbox. Accepts optional id, idleTimeoutMinutes, networkIsolation, and env overrides. Throws SandboxNotReadyError if this sandbox has not been started.
194
228
 
229
+ **derive** (`(options?) => RailwaySandbox`): Construct an unstarted sibling sandbox that inherits credentials and defaults. Accepts optional id, sandboxId, env, idleTimeoutMinutes, and checkpointName overrides. The derived sandbox uses options.checkpointName when set, otherwise it inherits the template checkpointName.
230
+
195
231
  ## Background processes
196
232
 
197
233
  `RailwaySandbox` includes a built-in process manager for spawning and managing background processes. Each spawned process runs as a Railway `exec` session.