-
-
Notifications
You must be signed in to change notification settings - Fork 218
feat: add Daytona Code Mode isolate driver #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mu-hashmi
wants to merge
4
commits into
TanStack:main
Choose a base branch
from
mu-hashmi:feat/daytona-adapter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/ai-isolate-daytona': minor | ||
| --- | ||
|
|
||
| Add the Daytona sandbox isolate driver for Code Mode. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # @tanstack/ai-isolate-daytona | ||
|
|
||
| Daytona sandbox driver for TanStack AI Code Mode. | ||
|
|
||
| This package runs generated JavaScript or TypeScript in a caller-provided Daytona sandbox and keeps TanStack tool implementations in your host process. When generated code calls an `external_*` tool, the sandbox returns a `need_tools` payload, the host executes the matching `ToolBinding.execute` callbacks, and the driver replays the code with accumulated tool results until it completes. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pnpm add @tanstack/ai-isolate-daytona @tanstack/ai-code-mode | ||
| ``` | ||
|
|
||
| If you use the official Daytona SDK to create sandboxes, install it in your app too: | ||
|
|
||
| ```bash | ||
| pnpm add @daytona/sdk | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```typescript | ||
| import { Daytona } from '@daytona/sdk' | ||
| import { createCodeMode } from '@tanstack/ai-code-mode' | ||
| import { createDaytonaIsolateDriver } from '@tanstack/ai-isolate-daytona' | ||
|
|
||
| const daytona = new Daytona() | ||
| const sandbox = await daytona.create({ language: 'typescript' }) | ||
|
|
||
| const driver = createDaytonaIsolateDriver({ | ||
| sandbox, | ||
| timeout: 30_000, | ||
| maxToolRounds: 10, | ||
| }) | ||
|
|
||
| const { tool, systemPrompt } = createCodeMode({ | ||
| driver, | ||
| tools: [myServerTool], | ||
| }) | ||
| ``` | ||
|
|
||
| The driver accepts a structural sandbox object with `sandbox.process.codeRun(...)`; it does not require `@daytona/sdk` as a package dependency. | ||
|
|
||
| ## API | ||
|
|
||
| ### `createDaytonaIsolateDriver(config)` | ||
|
|
||
| Creates an isolate driver that delegates Code Mode execution to a Daytona sandbox. | ||
|
|
||
| - `sandbox` (required): caller-owned object with `process.codeRun(code, params?, timeout?)` | ||
| - `timeout` (optional): total execution timeout across replay rounds, in milliseconds (default: `30000`) | ||
| - `maxToolRounds` (optional): maximum `need_tools` replay rounds per execution (default: `10`) | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Use a sandbox language/runtime that can execute the JavaScript emitted by Code Mode. | ||
| - Tool inputs and outputs must be JSON-serializable. | ||
| - Sandbox lifecycle, network access, filesystem contents, secrets, and cleanup are owned by your application. Creating a Code Mode context does not create or delete a Daytona sandbox. | ||
|
|
||
| ## How It Works | ||
|
|
||
| ```text | ||
| Host process Daytona sandbox | ||
| ------------ --------------- | ||
| createCodeMode + tools | ||
| wrap generated code ---------> run with process.codeRun | ||
| execute host tools <--------- need_tools requests | ||
| replay with toolResults ---------> continue execution | ||
| final result/logs <--------- done or error envelope | ||
| ``` | ||
|
|
||
| The host process talks directly to a Daytona sandbox through `process.codeRun`, while tool execution stays host-owned. | ||
|
|
||
| ## Validation | ||
|
|
||
| Run the package checks once the implementation files are present: | ||
|
|
||
| ```bash | ||
| pnpm --filter @tanstack/ai-isolate-daytona test:lib | ||
| pnpm --filter @tanstack/ai-isolate-daytona test:types | ||
| pnpm --filter @tanstack/ai-isolate-daytona test:eslint | ||
| pnpm --filter @tanstack/ai-isolate-daytona build | ||
| pnpm --filter @tanstack/ai-isolate-daytona test:build | ||
| ``` | ||
|
|
||
| Live Daytona validation should be gated on explicit credentials and sandbox setup in the implementation tests or a local smoke script. | ||
|
|
||
| ```bash | ||
| DAYTONA_LIVE_TEST=1 DAYTONA_API_KEY=... pnpm --filter @tanstack/ai-isolate-daytona test:live | ||
| ``` | ||
|
|
||
| The live suite is skipped unless `DAYTONA_LIVE_TEST=1` and `DAYTONA_API_KEY` are both present. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| { | ||
| "name": "@tanstack/ai-isolate-daytona", | ||
| "version": "0.0.1", | ||
| "description": "Daytona sandbox driver for TanStack AI Code Mode TypeScript execution.", | ||
| "author": "", | ||
| "license": "MIT", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/TanStack/ai.git", | ||
| "directory": "packages/ai-isolate-daytona" | ||
| }, | ||
| "type": "module", | ||
| "module": "./dist/esm/index.js", | ||
| "types": "./dist/esm/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/esm/index.d.ts", | ||
| "import": "./dist/esm/index.js" | ||
| } | ||
| }, | ||
| "sideEffects": false, | ||
| "engines": { | ||
| "node": ">=18" | ||
| }, | ||
| "files": [ | ||
| "dist", | ||
| "src" | ||
| ], | ||
| "scripts": { | ||
| "build": "vite build", | ||
| "clean": "premove ./build ./dist", | ||
| "lint:fix": "eslint ./src --fix", | ||
| "test:build": "publint --strict", | ||
| "test:eslint": "eslint ./src", | ||
| "test:live": "vitest --run tests/live.test.ts", | ||
| "test:lib": "vitest --passWithNoTests", | ||
| "test:lib:dev": "pnpm test:lib --watch", | ||
| "test:types": "tsc" | ||
| }, | ||
| "keywords": [ | ||
| "ai", | ||
| "ai-sdk", | ||
| "typescript", | ||
| "tanstack", | ||
| "code-mode", | ||
| "daytona", | ||
| "sandbox", | ||
| "isolate", | ||
| "code-execution" | ||
| ], | ||
| "peerDependencies": { | ||
| "@tanstack/ai-code-mode": "workspace:*" | ||
| }, | ||
| "devDependencies": { | ||
| "@daytona/sdk": "^0.180.0", | ||
| "@tanstack/ai-code-mode": "workspace:*", | ||
| "@vitest/coverage-v8": "4.0.14" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * @tanstack/ai-isolate-daytona | ||
| * | ||
| * Daytona sandbox driver for TanStack AI Code Mode. | ||
| * Execute LLM-generated code inside a caller-provided Daytona sandbox. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { createDaytonaIsolateDriver } from '@tanstack/ai-isolate-daytona' | ||
| * | ||
| * const driver = createDaytonaIsolateDriver({ sandbox }) | ||
| * ``` | ||
| * | ||
| * @packageDocumentation | ||
| */ | ||
|
|
||
| export { | ||
| createDaytonaIsolateDriver, | ||
| type DaytonaIsolateDriverConfig, | ||
| } from './isolate-driver' | ||
|
|
||
| export type { | ||
| DaytonaCodeRunArtifacts, | ||
| DaytonaCodeRunParams, | ||
| DaytonaCodeRunResponse, | ||
| DaytonaProcessLike, | ||
| DaytonaSandboxLike, | ||
| } from './types' | ||
|
|
||
| export type { | ||
| ExecutionResult, | ||
| IsolateConfig, | ||
| IsolateContext, | ||
| IsolateDriver, | ||
| NormalizedError, | ||
| } from '@tanstack/ai-code-mode' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
packageManagerto pin pnpm version.This manifest does not declare the required package manager pin, which can lead to inconsistent lockfile/tooling behavior across contributors.
Suggested fix
{ "name": "`@tanstack/ai-isolate-daytona`", "version": "0.0.1", + "packageManager": "pnpm@10.17.0", "description": "Daytona sandbox driver for TanStack AI Code Mode TypeScript execution.",As per coding guidelines "
**/package.json: Use pnpm@10.17.0 as the package manager for this repository".📝 Committable suggestion
🤖 Prompt for AI Agents