-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshell-example.ts
More file actions
53 lines (47 loc) · 1.34 KB
/
shell-example.ts
File metadata and controls
53 lines (47 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { ExecutionEngine, ContainerStrategy } from '../src';
async function main() {
const engine = new ExecutionEngine();
try {
// Create a session with per-execution strategy
const sessionId = await engine.createSession({
strategy: ContainerStrategy.PER_EXECUTION,
containerConfig: {
image: 'alpine:3.14',
environment: {
TERM: 'xterm-256color'
}
}
});
// Execute shell script that uses curl
const result = await engine.executeCode(sessionId, {
language: 'shell',
code: `#!/bin/sh
echo "Fetching example.com..."
curl -s https://example.com
echo "\\nDone!"`,
dependencies: ['curl'],
streamOutput: {
dependencyStdout: (data) => {
console.log('Dependency stdout:', data);
},
dependencyStderr: (data) => {
console.error('Dependency stderr:', data);
},
stdout: (data) => {
console.log('Container stdout:', data);
},
stderr: (data) => {
console.error('Container stderr:', data);
}
}
});
console.log('Execution Result:');
console.log('Exit Code:', result.exitCode);
console.log('Execution Time:', result.executionTime, 'ms');
} catch (error) {
console.error('Error:', error);
} finally {
await engine.cleanup();
}
}
main();