@computesdk/daytona 1.0.1 → 1.1.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/README.md CHANGED
@@ -1,85 +1,251 @@
1
1
  # @computesdk/daytona
2
2
 
3
- Daytona provider for ComputeSDK - Execute code in Daytona workspaces.
3
+ Daytona provider for ComputeSDK - Execute code in Daytona development workspaces.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- pnpm install @computesdk/daytona
8
+ npm install @computesdk/daytona
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
+ ### With ComputeSDK
14
+
13
15
  ```typescript
16
+ import { compute } from 'computesdk';
14
17
  import { daytona } from '@computesdk/daytona';
15
18
 
16
- // Create a Daytona sandbox
17
- const sandbox = daytona({
18
- runtime: 'python',
19
- timeout: 30000
19
+ // Set as default provider
20
+ compute.setConfig({
21
+ provider: daytona({ apiKey: process.env.DAYTONA_API_KEY })
20
22
  });
21
23
 
24
+ // Create sandbox
25
+ const sandbox = await compute.sandbox.create({});
26
+
22
27
  // Execute code
23
- const result = await sandbox.execute('print("Hello from Daytona!")');
28
+ const result = await sandbox.runCode('print("Hello from Daytona!")');
24
29
  console.log(result.stdout); // "Hello from Daytona!"
25
30
 
26
- // Run commands
27
- const cmdResult = await sandbox.runCommand('ls', ['-la']);
28
- console.log(cmdResult.stdout);
31
+ // Clean up
32
+ await compute.sandbox.destroy(sandbox.sandboxId);
33
+ ```
29
34
 
30
- // File operations
31
- await sandbox.filesystem.writeFile('/tmp/test.py', 'print("Hello World")');
32
- const content = await sandbox.filesystem.readFile('/tmp/test.py');
33
- console.log(content); // 'print("Hello World")'
35
+ ### Direct Usage
34
36
 
35
- // Clean up
36
- await sandbox.kill();
37
+ ```typescript
38
+ import { daytona } from '@computesdk/daytona';
39
+
40
+ // Create provider
41
+ const provider = daytona({
42
+ apiKey: 'your-api-key',
43
+ runtime: 'python'
44
+ });
45
+
46
+ // Use with compute singleton
47
+ const sandbox = await compute.sandbox.create({ provider });
37
48
  ```
38
49
 
39
50
  ## Configuration
40
51
 
41
- Set your Daytona API key as an environment variable:
52
+ ### Environment Variables
42
53
 
43
54
  ```bash
44
55
  export DAYTONA_API_KEY=your_api_key_here
45
56
  ```
46
57
 
58
+ ### Configuration Options
59
+
60
+ ```typescript
61
+ interface DaytonaConfig {
62
+ /** Daytona API key - if not provided, will use DAYTONA_API_KEY env var */
63
+ apiKey?: string;
64
+ /** Default runtime environment */
65
+ runtime?: 'python' | 'node';
66
+ /** Execution timeout in milliseconds */
67
+ timeout?: number;
68
+ }
69
+ ```
70
+
47
71
  ## Features
48
72
 
49
- - ✅ Code execution in Python, Node.js, and other runtimes
50
- - ✅ Command execution
51
- - ✅ File system operations (read, write, mkdir, etc.)
52
- - Interactive terminal sessions (not supported)
73
+ - ✅ **Code Execution** - Python and Node.js runtime support
74
+ - ✅ **Command Execution** - Run shell commands in workspace
75
+ - ✅ **Filesystem Operations** - Full file system access
76
+ - **Auto Runtime Detection** - Automatically detects Python vs Node.js
77
+ - ❌ **Interactive Terminals** - Not supported by Daytona SDK
53
78
 
54
79
  ## API Reference
55
80
 
56
- ### `daytona(config?)`
81
+ ### Code Execution
82
+
83
+ ```typescript
84
+ // Execute Python code
85
+ const result = await sandbox.runCode(`
86
+ import json
87
+ data = {"message": "Hello from Python"}
88
+ print(json.dumps(data))
89
+ `, 'python');
90
+
91
+ // Execute Node.js code
92
+ const result = await sandbox.runCode(`
93
+ const data = { message: "Hello from Node.js" };
94
+ console.log(JSON.stringify(data));
95
+ `, 'node');
96
+
97
+ // Auto-detection (based on code patterns)
98
+ const result = await sandbox.runCode('print("Auto-detected as Python")');
99
+ ```
100
+
101
+ ### Command Execution
102
+
103
+ ```typescript
104
+ // List files
105
+ const result = await sandbox.runCommand('ls', ['-la']);
106
+
107
+ // Install packages
108
+ const result = await sandbox.runCommand('pip', ['install', 'requests']);
109
+
110
+ // Run scripts
111
+ const result = await sandbox.runCommand('python', ['script.py']);
112
+ ```
113
+
114
+ ### Filesystem Operations
115
+
116
+ ```typescript
117
+ // Write file
118
+ await sandbox.filesystem.writeFile('/workspace/hello.py', 'print("Hello World")');
119
+
120
+ // Read file
121
+ const content = await sandbox.filesystem.readFile('/workspace/hello.py');
122
+
123
+ // Create directory
124
+ await sandbox.filesystem.mkdir('/workspace/data');
57
125
 
58
- Creates a new Daytona sandbox instance.
126
+ // List directory contents
127
+ const files = await sandbox.filesystem.readdir('/workspace');
59
128
 
60
- **Parameters:**
61
- - `config` (optional): Configuration object
62
- - `runtime`: Runtime environment ('python', 'node', etc.)
63
- - `timeout`: Execution timeout in milliseconds
129
+ // Check if file exists
130
+ const exists = await sandbox.filesystem.exists('/workspace/hello.py');
64
131
 
65
- **Returns:** `DaytonaProvider` instance
132
+ // Remove file or directory
133
+ await sandbox.filesystem.remove('/workspace/hello.py');
134
+ ```
135
+
136
+ ### Sandbox Management
137
+
138
+ ```typescript
139
+ // Get sandbox info
140
+ const info = await sandbox.getInfo();
141
+ console.log(info.id, info.provider, info.status);
142
+
143
+ // List all sandboxes
144
+ const sandboxes = await compute.sandbox.list(provider);
145
+
146
+ // Get existing sandbox
147
+ const existing = await compute.sandbox.getById(provider, 'sandbox-id');
148
+
149
+ // Destroy sandbox
150
+ await compute.sandbox.destroy(provider, 'sandbox-id');
151
+ ```
152
+
153
+ ## Runtime Detection
154
+
155
+ The provider automatically detects the runtime based on code patterns:
156
+
157
+ **Python indicators:**
158
+ - `print(` statements
159
+ - `import` statements
160
+ - `def` function definitions
161
+ - Python-specific syntax (`f"`, `__`, etc.)
162
+
163
+ **Default:** Node.js for all other cases
164
+
165
+ ## Error Handling
166
+
167
+ ```typescript
168
+ try {
169
+ const result = await sandbox.runCode('invalid code');
170
+ } catch (error) {
171
+ if (error.message.includes('Syntax error')) {
172
+ console.error('Code has syntax errors');
173
+ } else if (error.message.includes('authentication failed')) {
174
+ console.error('Check your DAYTONA_API_KEY');
175
+ } else if (error.message.includes('quota exceeded')) {
176
+ console.error('Daytona usage limits reached');
177
+ }
178
+ }
179
+ ```
180
+
181
+ ## Web Framework Integration
182
+
183
+ Use with web frameworks via the request handler:
184
+
185
+ ```typescript
186
+ import { handleComputeRequest } from 'computesdk';
187
+ import { daytona } from '@computesdk/daytona';
66
188
 
67
- ### Methods
189
+ export async function POST(request: Request) {
190
+ return handleComputeRequest({
191
+ request,
192
+ provider: daytona({ apiKey: process.env.DAYTONA_API_KEY })
193
+ });
194
+ }
195
+ ```
196
+
197
+ ## Examples
68
198
 
69
- - `execute(code, runtime?)`: Execute code in the sandbox
70
- - `runCode(code, runtime?)`: Alias for execute
71
- - `runCommand(command, args?)`: Execute shell commands
72
- - `kill()`: Terminate the sandbox
73
- - `getInfo()`: Get sandbox information
199
+ ### Data Processing
74
200
 
75
- ### File System
201
+ ```typescript
202
+ const result = await sandbox.runCode(`
203
+ import json
204
+
205
+ # Process data
206
+ data = [1, 2, 3, 4, 5]
207
+ result = {
208
+ "sum": sum(data),
209
+ "average": sum(data) / len(data),
210
+ "max": max(data)
211
+ }
212
+
213
+ print(json.dumps(result))
214
+ `);
215
+
216
+ const output = JSON.parse(result.stdout);
217
+ console.log(output); // { sum: 15, average: 3, max: 5 }
218
+ ```
76
219
 
77
- - `filesystem.readFile(path)`: Read file contents
78
- - `filesystem.writeFile(path, content)`: Write file contents
79
- - `filesystem.mkdir(path)`: Create directory
80
- - `filesystem.readdir(path)`: List directory contents
81
- - `filesystem.exists(path)`: Check if file/directory exists
82
- - `filesystem.remove(path)`: Remove file/directory
220
+ ### File Processing
221
+
222
+ ```typescript
223
+ // Create data file
224
+ await sandbox.filesystem.writeFile('/workspace/data.json',
225
+ JSON.stringify({ users: ['Alice', 'Bob', 'Charlie'] })
226
+ );
227
+
228
+ // Process file
229
+ const result = await sandbox.runCode(`
230
+ import json
231
+
232
+ with open('/workspace/data.json', 'r') as f:
233
+ data = json.load(f)
234
+
235
+ # Process users
236
+ user_count = len(data['users'])
237
+ print(f"Found {user_count} users")
238
+
239
+ # Save result
240
+ result = {"user_count": user_count, "processed": True}
241
+ with open('/workspace/result.json', 'w') as f:
242
+ json.dump(result, f)
243
+ `);
244
+
245
+ // Read result
246
+ const resultData = await sandbox.filesystem.readFile('/workspace/result.json');
247
+ console.log(JSON.parse(resultData));
248
+ ```
83
249
 
84
250
  ## License
85
251
 
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
- import { Runtime, Provider, ProviderSandboxManager } from 'computesdk';
1
+ import * as computesdk from 'computesdk';
2
+ import { Runtime } from 'computesdk';
2
3
 
3
4
  /**
4
5
  * Daytona-specific configuration options
@@ -12,16 +13,8 @@ interface DaytonaConfig {
12
13
  timeout?: number;
13
14
  }
14
15
  /**
15
- * Daytona Provider implementation
16
+ * Create a Daytona provider instance using the factory pattern
16
17
  */
17
- declare class DaytonaProvider implements Provider {
18
- readonly name = "daytona";
19
- readonly sandbox: ProviderSandboxManager;
20
- constructor(config?: DaytonaConfig);
21
- }
22
- /**
23
- * Create a Daytona provider instance
24
- */
25
- declare function daytona(config?: DaytonaConfig): DaytonaProvider;
18
+ declare const daytona: (config: DaytonaConfig) => computesdk.Provider;
26
19
 
27
- export { type DaytonaConfig, DaytonaProvider, daytona };
20
+ export { type DaytonaConfig, daytona };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Runtime, Provider, ProviderSandboxManager } from 'computesdk';
1
+ import * as computesdk from 'computesdk';
2
+ import { Runtime } from 'computesdk';
2
3
 
3
4
  /**
4
5
  * Daytona-specific configuration options
@@ -12,16 +13,8 @@ interface DaytonaConfig {
12
13
  timeout?: number;
13
14
  }
14
15
  /**
15
- * Daytona Provider implementation
16
+ * Create a Daytona provider instance using the factory pattern
16
17
  */
17
- declare class DaytonaProvider implements Provider {
18
- readonly name = "daytona";
19
- readonly sandbox: ProviderSandboxManager;
20
- constructor(config?: DaytonaConfig);
21
- }
22
- /**
23
- * Create a Daytona provider instance
24
- */
25
- declare function daytona(config?: DaytonaConfig): DaytonaProvider;
18
+ declare const daytona: (config: DaytonaConfig) => computesdk.Provider;
26
19
 
27
- export { type DaytonaConfig, DaytonaProvider, daytona };
20
+ export { type DaytonaConfig, daytona };