@computesdk/daytona 1.1.0 → 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 +207 -41
- package/package.json +2 -2
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
|
-
|
|
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
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
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.
|
|
28
|
+
const result = await sandbox.runCode('print("Hello from Daytona!")');
|
|
24
29
|
console.log(result.stdout); // "Hello from Daytona!"
|
|
25
30
|
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
// Clean up
|
|
32
|
+
await compute.sandbox.destroy(sandbox.sandboxId);
|
|
33
|
+
```
|
|
29
34
|
|
|
30
|
-
|
|
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
|
-
|
|
36
|
-
|
|
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
|
-
|
|
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
|
|
50
|
-
- ✅ Command
|
|
51
|
-
- ✅
|
|
52
|
-
-
|
|
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
|
-
###
|
|
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
|
-
|
|
126
|
+
// List directory contents
|
|
127
|
+
const files = await sandbox.filesystem.readdir('/workspace');
|
|
59
128
|
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@computesdk/daytona",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Daytona provider for ComputeSDK",
|
|
5
5
|
"author": "Garrison",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@daytonaio/sdk": "^0.25.0",
|
|
22
|
-
"computesdk": "1.1.
|
|
22
|
+
"computesdk": "1.1.1"
|
|
23
23
|
},
|
|
24
24
|
"keywords": [
|
|
25
25
|
"daytona",
|