@upcrawl/sdk 1.3.0 → 1.3.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 +58 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -148,6 +148,41 @@ const result = await Upcrawl.generatePdfFromUrl({
|
|
|
148
148
|
console.log(result.url); // Download URL for the PDF
|
|
149
149
|
```
|
|
150
150
|
|
|
151
|
+
### Execute Code
|
|
152
|
+
|
|
153
|
+
Run code in an isolated sandbox environment:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
const result = await Upcrawl.executeCode({
|
|
157
|
+
code: 'print("Hello, World!")',
|
|
158
|
+
language: 'python'
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
console.log(result.stdout); // "Hello, World!\n"
|
|
162
|
+
console.log(result.exitCode); // 0
|
|
163
|
+
console.log(result.executionTimeMs); // 95.23
|
|
164
|
+
console.log(result.memoryUsageMb); // 8.45
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Each execution runs in its own isolated subprocess inside a Kata micro-VM with no network access. Code is cleaned up immediately after execution.
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
// Multi-line code with imports
|
|
171
|
+
const result = await Upcrawl.executeCode({
|
|
172
|
+
code: `
|
|
173
|
+
import json
|
|
174
|
+
data = {"name": "Upcrawl", "version": 1}
|
|
175
|
+
print(json.dumps(data, indent=2))
|
|
176
|
+
`
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
console.log(result.stdout);
|
|
180
|
+
// {
|
|
181
|
+
// "name": "Upcrawl",
|
|
182
|
+
// "version": 1
|
|
183
|
+
// }
|
|
184
|
+
```
|
|
185
|
+
|
|
151
186
|
### Domain Filtering
|
|
152
187
|
|
|
153
188
|
Filter search results by domain:
|
|
@@ -249,7 +284,9 @@ import Upcrawl, {
|
|
|
249
284
|
BatchScrapeOptions,
|
|
250
285
|
BatchScrapeResponse,
|
|
251
286
|
GeneratePdfOptions,
|
|
252
|
-
PdfResponse
|
|
287
|
+
PdfResponse,
|
|
288
|
+
ExecuteCodeOptions,
|
|
289
|
+
ExecuteCodeResponse
|
|
253
290
|
} from '@upcrawl/sdk';
|
|
254
291
|
|
|
255
292
|
const options: ScrapeOptions = {
|
|
@@ -275,6 +312,7 @@ const result: ScrapeResponse = await Upcrawl.scrape(options);
|
|
|
275
312
|
| `Upcrawl.search(options)` | Search the web |
|
|
276
313
|
| `Upcrawl.generatePdf(options)` | Generate PDF from HTML |
|
|
277
314
|
| `Upcrawl.generatePdfFromUrl(options)` | Generate PDF from a URL |
|
|
315
|
+
| `Upcrawl.executeCode(options)` | Execute code in an isolated sandbox |
|
|
278
316
|
|
|
279
317
|
### Scrape Options
|
|
280
318
|
|
|
@@ -323,6 +361,25 @@ const result: ScrapeResponse = await Upcrawl.scrape(options);
|
|
|
323
361
|
| `printBackground` | `boolean` | Print background graphics |
|
|
324
362
|
| `timeoutMs` | `number` | Timeout (5000-120000) |
|
|
325
363
|
|
|
364
|
+
### Execute Code Options
|
|
365
|
+
|
|
366
|
+
| Option | Type | Description |
|
|
367
|
+
|--------|------|-------------|
|
|
368
|
+
| `code` | `string` | Code to execute (required) |
|
|
369
|
+
| `language` | `'python'` | Language runtime (default: python) |
|
|
370
|
+
|
|
371
|
+
### Execute Code Response
|
|
372
|
+
|
|
373
|
+
| Field | Type | Description |
|
|
374
|
+
|-------|------|-------------|
|
|
375
|
+
| `stdout` | `string` | Standard output |
|
|
376
|
+
| `stderr` | `string` | Standard error |
|
|
377
|
+
| `exitCode` | `number` | Exit code (0 = success, 124 = timeout) |
|
|
378
|
+
| `executionTimeMs` | `number` | Execution time in milliseconds |
|
|
379
|
+
| `timedOut` | `boolean` | Whether execution timed out |
|
|
380
|
+
| `memoryUsageMb` | `number` | Peak memory usage in MB |
|
|
381
|
+
| `cost` | `number` | Cost in USD |
|
|
382
|
+
|
|
326
383
|
## License
|
|
327
384
|
|
|
328
385
|
MIT
|