@mastra/daytona 0.0.1

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/LICENSE.md ADDED
@@ -0,0 +1,15 @@
1
+ # Apache License 2.0
2
+
3
+ Copyright (c) 2025 Kepler Software, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,168 @@
1
+ # @mastra/daytona
2
+
3
+ Daytona cloud sandbox provider for [Mastra](https://mastra.ai) workspaces.
4
+
5
+ Implements the `WorkspaceSandbox` interface using [Daytona](https://www.daytona.io/) sandboxes. Supports multiple runtimes, resource configuration, volumes, snapshots, streaming output, and sandbox reconnection.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @mastra/daytona @mastra/core
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Basic
16
+
17
+ ```typescript
18
+ import { Workspace } from '@mastra/core/workspace';
19
+ import { DaytonaSandbox } from '@mastra/daytona';
20
+
21
+ const sandbox = new DaytonaSandbox({
22
+ language: 'typescript',
23
+ timeout: 60_000,
24
+ });
25
+
26
+ const workspace = new Workspace({ sandbox });
27
+ await workspace.init();
28
+
29
+ const result = await workspace.sandbox.executeCommand('echo', ['Hello!']);
30
+ console.log(result.stdout); // "Hello!"
31
+
32
+ await workspace.destroy();
33
+ ```
34
+
35
+ ### Snapshot
36
+
37
+ Use a pre-built snapshot to skip environment setup time:
38
+
39
+ ```typescript
40
+ const sandbox = new DaytonaSandbox({
41
+ snapshot: 'my-snapshot-id',
42
+ timeout: 60_000,
43
+ });
44
+ ```
45
+
46
+ ### Custom image with resources
47
+
48
+ Use a custom Docker image with specific resource allocation:
49
+
50
+ ```typescript
51
+ const sandbox = new DaytonaSandbox({
52
+ image: 'node:20-slim',
53
+ resources: { cpu: 2, memory: 4, disk: 4 },
54
+ language: 'typescript',
55
+ });
56
+ ```
57
+
58
+ ### Ephemeral sandbox
59
+
60
+ For one-shot tasks — sandbox is deleted immediately on stop:
61
+
62
+ ```typescript
63
+ const sandbox = new DaytonaSandbox({
64
+ ephemeral: true,
65
+ language: 'python',
66
+ });
67
+ ```
68
+
69
+ ### Streaming output
70
+
71
+ Stream command output in real time via callbacks:
72
+
73
+ ```typescript
74
+ await sandbox.executeCommand('bash', ['-c', 'for i in 1 2 3; do echo "line $i"; sleep 1; done'], {
75
+ onStdout: chunk => process.stdout.write(chunk),
76
+ onStderr: chunk => process.stderr.write(chunk),
77
+ });
78
+ ```
79
+
80
+ ### Network isolation
81
+
82
+ Restrict outbound network access:
83
+
84
+ ```typescript
85
+ const sandbox = new DaytonaSandbox({
86
+ networkBlockAll: true,
87
+ networkAllowList: '10.0.0.0/8,192.168.0.0/16',
88
+ });
89
+ ```
90
+
91
+ ### With Agent
92
+
93
+ Wire a Daytona sandbox into a Mastra agent to give it code execution in an isolated sandbox:
94
+
95
+ ```typescript
96
+ import { Agent } from '@mastra/core/agent';
97
+ import { Workspace } from '@mastra/core/workspace';
98
+ import { DaytonaSandbox } from '@mastra/daytona';
99
+
100
+ const sandbox = new DaytonaSandbox({
101
+ language: 'typescript',
102
+ timeout: 120_000,
103
+ });
104
+
105
+ const workspace = new Workspace({ sandbox });
106
+
107
+ const agent = new Agent({
108
+ id: 'code-agent',
109
+ name: 'Code Agent',
110
+ instructions: 'You are a coding assistant working in this workspace.',
111
+ model: 'anthropic/claude-sonnet-4-6',
112
+ workspace,
113
+ });
114
+
115
+ const response = await agent.generate('Print "Hello, world!" and show the current working directory.');
116
+
117
+ console.log(response.text);
118
+ // I'll run both commands simultaneously!
119
+ //
120
+ // Here are the results:
121
+ //
122
+ // 1. **Hello, world!** — Successfully printed the message.
123
+ // 2. **Current Working Directory** — `/home/daytona`
124
+ //
125
+ // Both commands ran in parallel and completed successfully!
126
+ ```
127
+
128
+ ## Configuration
129
+
130
+ | Option | Type | Default | Description |
131
+ | --------------------- | --------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
132
+ | `id` | `string` | auto-generated | Sandbox identifier |
133
+ | `apiKey` | `string` | `DAYTONA_API_KEY` env | API key |
134
+ | `apiUrl` | `string` | `DAYTONA_API_URL` env | API endpoint |
135
+ | `target` | `string` | `DAYTONA_TARGET` env | Runner region |
136
+ | `timeout` | `number` | `300000` | Default execution timeout (ms) |
137
+ | `language` | `string` | `'typescript'` | Runtime language |
138
+ | `snapshot` | `string` | — | Pre-built snapshot ID. Takes precedence over `image`. |
139
+ | `image` | `string` | — | Docker image for sandbox creation. Triggers image-based creation when set. Can be combined with `resources`. Ignored when `snapshot` is set. |
140
+ | `resources` | `object` | SDK defaults | `{ cpu, memory, disk }`. Only used with `image`. |
141
+ | `env` | `object` | `{}` | Environment variables |
142
+ | `labels` | `object` | `{}` | Custom metadata labels |
143
+ | `name` | `string` | sandbox `id` | Sandbox display name |
144
+ | `user` | `string` | `daytona` | OS user to run commands as |
145
+ | `public` | `boolean` | `false` | Make port previews public |
146
+ | `ephemeral` | `boolean` | `false` | Delete sandbox immediately on stop |
147
+ | `autoStopInterval` | `number` | `15` | Auto-stop interval in minutes (0 = disabled) |
148
+ | `autoArchiveInterval` | `number` | `7 days` | Auto-archive interval in minutes (0 = 7 days) |
149
+ | `autoDeleteInterval` | `number` | `disabled` | Auto-delete interval in minutes (negative = disabled, 0 = delete on stop) |
150
+ | `volumes` | `array` | — | `[{ volumeId, mountPath }]` |
151
+ | `networkBlockAll` | `boolean` | `false` | Block all network access |
152
+ | `networkAllowList` | `string` | — | Comma-separated allowed CIDR addresses |
153
+
154
+ ## Direct SDK Access
155
+
156
+ Access the underlying Daytona `Sandbox` instance for filesystem, git, and other operations not exposed through WorkspaceSandbox:
157
+
158
+ ```typescript
159
+ const daytonaSandbox = sandbox.instance;
160
+
161
+ await daytonaSandbox.fs.uploadFile(Buffer.from('data'), '/tmp/file.txt');
162
+
163
+ await daytonaSandbox.git.clone('https://github.com/org/repo', '/workspace/repo');
164
+ ```
165
+
166
+ ## License
167
+
168
+ Apache-2.0