@mastra/daytona 0.8.0 → 0.9.0-alpha.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/CHANGELOG.md CHANGED
@@ -1,5 +1,63 @@
1
1
  # @mastra/daytona
2
2
 
3
+ ## 0.9.0-alpha.1
4
+
5
+ ### Minor Changes
6
+
7
+ - Added a `secrets` option to `DaytonaSandbox` for injecting Daytona Secrets into sandboxes. Map environment variable names to Daytona Secret names and the real value is substituted into HTTPS request headers at egress — the raw credential never enters the sandbox. ([#22322](https://github.com/mastra-ai/mastra/pull/22322))
8
+
9
+ ```typescript
10
+ const sandbox = new DaytonaSandbox({
11
+ secrets: {
12
+ GITHUB_TOKEN: 'github-token',
13
+ },
14
+ });
15
+ ```
16
+
17
+ Closes https://github.com/mastra-ai/mastra/issues/22314
18
+
19
+ ### Patch Changes
20
+
21
+ - Fixed a leak where every command left its process handle behind, by removing Daytona's own `executeCommand` in favour of the shared one, which releases them. ([#21984](https://github.com/mastra-ai/mastra/pull/21984))
22
+
23
+ Command results now match every other provider: `command` holds the full command string, and the separate `args` array is gone.
24
+
25
+ ```typescript
26
+ const result = await sandbox.executeCommand('echo', ['hello']);
27
+ // before: result.command === 'echo', result.args === ['hello']
28
+ // after: result.command === 'echo hello', result.args === undefined
29
+ ```
30
+
31
+ - Starting a sandbox now reports whether it created a fresh sandbox or reconnected to an existing one, so an `onStart` handler can run first-time setup only when it's actually needed: ([#21984](https://github.com/mastra-ai/mastra/pull/21984))
32
+
33
+ ```typescript
34
+ new E2BSandbox({
35
+ id: 'session-1',
36
+ onStart: async ({ outcome }) => {
37
+ if (outcome === 'created') await cloneRepo();
38
+ },
39
+ });
40
+ ```
41
+
42
+ - Updated dependencies [[`4ff3ee2`](https://github.com/mastra-ai/mastra/commit/4ff3ee2bff7ed07528b4817f8f49639031c72a4d), [`c24754c`](https://github.com/mastra-ai/mastra/commit/c24754c1fb6fe144e5051e536e98c8a18b0214ac), [`45dd6ee`](https://github.com/mastra-ai/mastra/commit/45dd6ee089bd7df0d0c98a10098e483fd388e04a), [`32d3583`](https://github.com/mastra-ai/mastra/commit/32d358332cb8ac2306b83b73cf3536e74dbd435e), [`aca2869`](https://github.com/mastra-ai/mastra/commit/aca2869b2031982f3c4a2f52525c9be7cf123ef8)]:
43
+ - @mastra/core@1.62.0-alpha.11
44
+
45
+ ## 0.8.1-alpha.0
46
+
47
+ ### Patch Changes
48
+
49
+ - Honor the sandbox runtime environment (`setEnv()`/`getEnv()` from `@mastra/core`) in every workspace sandbox provider. Environment variables set after construction now reach subsequent commands on all providers: ([#22250](https://github.com/mastra-ai/mastra/pull/22250))
50
+
51
+ - Process-manager-routed providers (E2B, Blaxel, Cloudflare, Daytona, Docker, Modal, Vercel microVM spawns) inherit the merge from the core spawn wrapper; their duplicated per-manager env plumbing is removed.
52
+ - Providers with their own exec transports (AgentCore, Apple Container, Railway, Vercel microVM and serverless `executeCommand`, Platform's private-network, WebSocket lease, and E2B lease paths) now merge `getEnv()` under per-call env.
53
+
54
+ Constructor `env` continues to behave as before: it seeds the sandbox runtime environment, and providers that bake env into the VM or container at creation time (Docker, Modal, Railway, Apple Container, Vercel, Platform) still do so. Per-call `env` on `executeCommand` still takes precedence for that command only.
55
+
56
+ Removed exported types (minor bump for these two packages): `BlaxelProcessManagerOptions` from `@mastra/blaxel` and `RailwayProcessManagerOptions` from `@mastra/railway`. Both existed only to pass `env` into a process manager constructed by hand; the core spawn wrapper now owns that merge, so the option and its type are gone.
57
+
58
+ - Updated dependencies [[`aa3a85d`](https://github.com/mastra-ai/mastra/commit/aa3a85daf094c683bb97efdf4b6a696d2e474af5), [`d29d06f`](https://github.com/mastra-ai/mastra/commit/d29d06fe00bbd35b4571150ea04c59d2ed783c71), [`e6516df`](https://github.com/mastra-ai/mastra/commit/e6516dfcdae4f4ac0e7971d84359a81385ee602f), [`0b2a3d1`](https://github.com/mastra-ai/mastra/commit/0b2a3d1783875c5b97b7b36ab3d03d7360e0dde7), [`6bb5d71`](https://github.com/mastra-ai/mastra/commit/6bb5d7193fe9166b219f0fccae17db7a5ae86e65), [`57de7d6`](https://github.com/mastra-ai/mastra/commit/57de7d644ba7146edb4e9e6111ec4fa98c3a59e9), [`e8e299c`](https://github.com/mastra-ai/mastra/commit/e8e299cc6abdfc39947e2fec25803493015d3882), [`edfc548`](https://github.com/mastra-ai/mastra/commit/edfc548886bc7bae17b681f8b6b41a47eb32bcd2), [`a8a4871`](https://github.com/mastra-ai/mastra/commit/a8a4871215f51da95c47129602157ce5372f634a), [`5165cdc`](https://github.com/mastra-ai/mastra/commit/5165cdcdcf50e144bb8113278535196cc9b07065), [`6bb5d71`](https://github.com/mastra-ai/mastra/commit/6bb5d7193fe9166b219f0fccae17db7a5ae86e65), [`9ee8120`](https://github.com/mastra-ai/mastra/commit/9ee8120ce17f76b9f617489e05a283353742690a), [`d975e92`](https://github.com/mastra-ai/mastra/commit/d975e924d4936f46c386bd3dee39c671720289f6), [`1cfa878`](https://github.com/mastra-ai/mastra/commit/1cfa8784d8da0dfaa0317e5048bc48b6084a5ea5), [`c118318`](https://github.com/mastra-ai/mastra/commit/c1183181c9804303db4b511c2e2648f8b714712b), [`fc07c64`](https://github.com/mastra-ai/mastra/commit/fc07c6465043e08e99193a6751a01c56ffc2e7a1), [`542dee2`](https://github.com/mastra-ai/mastra/commit/542dee254167f974ff8cbbbfc0ce10f9a2616a7b), [`a58483c`](https://github.com/mastra-ai/mastra/commit/a58483cff1a9d41fce7c931843f48cb0ac450f64), [`a58483c`](https://github.com/mastra-ai/mastra/commit/a58483cff1a9d41fce7c931843f48cb0ac450f64), [`895e9df`](https://github.com/mastra-ai/mastra/commit/895e9dfc17d6f34299eca64e317ded9e5f5e5ef8)]:
59
+ - @mastra/core@1.62.0-alpha.8
60
+
3
61
  ## 0.8.0
4
62
 
5
63
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -525,7 +525,7 @@ var DaytonaProcessManager = class extends _mastra_core_workspace.SandboxProcessM
525
525
  _spawnCounter = 0;
526
526
  _defaultTimeout;
527
527
  constructor(opts = {}) {
528
- super({ env: opts.env });
528
+ super();
529
529
  this._defaultTimeout = opts.defaultTimeout;
530
530
  }
531
531
  async spawn(command, options = {}) {
@@ -534,11 +534,7 @@ var DaytonaProcessManager = class extends _mastra_core_workspace.SandboxProcessM
534
534
  timeout: options.timeout ?? this._defaultTimeout,
535
535
  cwd: options.cwd ?? this.sandbox.mounts?.entries?.keys().next().value
536
536
  };
537
- const mergedEnv = {
538
- ...this.env,
539
- ...effectiveOptions.env
540
- };
541
- const envs = Object.fromEntries(Object.entries(mergedEnv).filter((entry) => entry[1] !== void 0));
537
+ const envs = Object.fromEntries(Object.entries(effectiveOptions.env ?? {}).filter((entry) => entry[1] !== void 0));
542
538
  const sessionCommand = buildSpawnCommand(command, effectiveOptions.cwd, envs);
543
539
  return this.sandbox.retryOnDead(async () => {
544
540
  const sandbox = this.sandbox.daytona;
@@ -697,7 +693,6 @@ var DaytonaSandbox = class DaytonaSandbox extends _mastra_core_workspace.MastraS
697
693
  timeout;
698
694
  language;
699
695
  resources;
700
- env;
701
696
  labels;
702
697
  snapshotId;
703
698
  image;
@@ -713,22 +708,19 @@ var DaytonaSandbox = class DaytonaSandbox extends _mastra_core_workspace.MastraS
713
708
  networkBlockAll;
714
709
  networkAllowList;
715
710
  domainAllowList;
711
+ secrets;
716
712
  connectionOpts;
717
713
  _constructorOptions;
718
714
  constructor(options = {}) {
719
715
  super({
720
716
  ...options,
721
717
  name: "DaytonaSandbox",
722
- processes: new DaytonaProcessManager({
723
- env: options.env,
724
- defaultTimeout: options.timeout ?? 3e5
725
- })
718
+ processes: new DaytonaProcessManager({ defaultTimeout: options.timeout ?? 3e5 })
726
719
  });
727
720
  this.id = options.id ?? this.generateId();
728
721
  this.timeout = options.timeout ?? 3e5;
729
722
  this.language = options.language ?? "typescript";
730
723
  this.resources = options.resources;
731
- this.env = options.env ?? {};
732
724
  this.labels = options.labels ?? {};
733
725
  this.snapshotId = options.snapshot;
734
726
  this.image = options.image;
@@ -743,6 +735,7 @@ var DaytonaSandbox = class DaytonaSandbox extends _mastra_core_workspace.MastraS
743
735
  this.networkBlockAll = options.networkBlockAll;
744
736
  this.networkAllowList = options.networkAllowList;
745
737
  this.domainAllowList = options.domainAllowList;
738
+ this.secrets = options.secrets;
746
739
  this.connectionOpts = {
747
740
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
748
741
  ...options.apiUrl !== void 0 && { apiUrl: options.apiUrl },
@@ -800,26 +793,35 @@ var DaytonaSandbox = class DaytonaSandbox extends _mastra_core_workspace.MastraS
800
793
  return this.daytona;
801
794
  }
802
795
  /**
803
- * Start the Daytona sandbox.
804
- * Reconnects to an existing sandbox with the same logical ID if one exists,
805
- * otherwise creates a new sandbox instance.
796
+ * Acquisition primitives (base-orchestrated start): the base derives
797
+ * `created` structurally from whether an existing sandbox was found, so
798
+ * reconnecting to one with the same logical ID reports `connected`.
799
+ * Lookup errors other than not-found propagate deliberately — creating a
800
+ * duplicate sandbox on a transient/auth error would be worse than failing.
806
801
  */
807
- async start() {
808
- if (this._sandbox) return;
802
+ async find() {
803
+ if (this._sandbox) return this._sandbox;
809
804
  if (!this._daytona) this._daytona = new _daytonaio_sdk.Daytona(this.connectionOpts);
810
- const existing = await this.findExistingSandbox();
811
- if (existing) {
812
- this._sandbox = existing;
813
- this._daytonaSandboxId = existing.id;
814
- this._createdAt = existing.createdAt ? new Date(existing.createdAt) : /* @__PURE__ */ new Date();
815
- this.logger.debug(`${LOG_PREFIX} Reconnected to existing sandbox ${existing.id} for: ${this.id}`);
816
- const expectedPaths = Array.from(this.mounts.entries.keys());
817
- this.logger.debug(`${LOG_PREFIX} Running mount reconciliation...`);
818
- await this.reconcileMounts(expectedPaths);
819
- this.logger.debug(`${LOG_PREFIX} Mount reconciliation complete`);
820
- await this.detectWorkingDir();
821
- return;
805
+ return await this.findExistingSandbox() ?? void 0;
806
+ }
807
+ async connect(existing) {
808
+ if (existing === this._sandbox) return;
809
+ if (existing.state !== _daytonaio_sdk.SandboxState.STARTED) {
810
+ this.logger.debug(`${LOG_PREFIX} Restarting sandbox ${existing.id} (state: ${existing.state})`);
811
+ await this.waitForStableStateAndStart(existing);
822
812
  }
813
+ this._sandbox = existing;
814
+ this._daytonaSandboxId = existing.id;
815
+ this._createdAt = existing.createdAt ? new Date(existing.createdAt) : /* @__PURE__ */ new Date();
816
+ this.logger.debug(`${LOG_PREFIX} Reconnected to existing sandbox ${existing.id} for: ${this.id}`);
817
+ const expectedPaths = Array.from(this.mounts.entries.keys());
818
+ this.logger.debug(`${LOG_PREFIX} Running mount reconciliation...`);
819
+ await this.reconcileMounts(expectedPaths);
820
+ this.logger.debug(`${LOG_PREFIX} Mount reconciliation complete`);
821
+ await this.detectWorkingDir();
822
+ }
823
+ async create() {
824
+ if (!this._daytona) this._daytona = new _daytonaio_sdk.Daytona(this.connectionOpts);
823
825
  this.logger.debug(`${LOG_PREFIX} Creating sandbox for: ${this.id}`);
824
826
  const baseParams = compact({
825
827
  language: this.language,
@@ -837,7 +839,8 @@ var DaytonaSandbox = class DaytonaSandbox extends _mastra_core_workspace.MastraS
837
839
  public: this.sandboxPublic,
838
840
  networkBlockAll: this.networkBlockAll,
839
841
  networkAllowList: this.networkAllowList,
840
- domainAllowList: this.domainAllowList
842
+ domainAllowList: this.domainAllowList,
843
+ secrets: this.secrets
841
844
  });
842
845
  if (this.resources && !this.image) this.logger.warn(`${LOG_PREFIX} 'resources' option requires 'image' to take effect — falling back to snapshot-based creation without custom resources`);
843
846
  const createParams = this.image && !this.snapshotId ? compact({
@@ -942,18 +945,6 @@ var DaytonaSandbox = class DaytonaSandbox extends _mastra_core_workspace.MastraS
942
945
  return parts.join(" ");
943
946
  }
944
947
  /**
945
- * Execute a command in the sandbox and return the result.
946
- */
947
- async executeCommand(command, args = [], options = {}) {
948
- await this.ensureRunning();
949
- const fullCommand = args.length > 0 ? `${command} ${args.map(shellQuote).join(" ")}` : command;
950
- return {
951
- ...await (await this.processes.spawn(fullCommand, options)).wait(),
952
- command,
953
- args
954
- };
955
- }
956
- /**
957
948
  * Bulk-write files into the sandbox filesystem via the SDK's native upload.
958
949
  */
959
950
  async writeFiles(files) {
@@ -1324,10 +1315,6 @@ var DaytonaSandbox = class DaytonaSandbox extends _mastra_core_workspace.MastraS
1324
1315
  } catch {}
1325
1316
  return null;
1326
1317
  }
1327
- if (state !== _daytonaio_sdk.SandboxState.STARTED) {
1328
- this.logger.debug(`${LOG_PREFIX} Restarting sandbox ${sandbox.id} (state: ${state})`);
1329
- await this.waitForStableStateAndStart(sandbox);
1330
- }
1331
1318
  return sandbox;
1332
1319
  }
1333
1320
  /**