-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest-copilot-sandbox.ts
More file actions
63 lines (50 loc) · 1.74 KB
/
test-copilot-sandbox.ts
File metadata and controls
63 lines (50 loc) · 1.74 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
54
55
56
57
58
59
60
61
62
63
import { SandboxManager, type SandboxRuntimeConfig } from '@anthropic-ai/sandbox-runtime'
import { spawn } from 'child_process'
import { readFileSync } from 'fs'
import { join } from 'path'
async function main() {
// Load the sandbox configuration from .srt-settings.json
const configPath = join(process.cwd(), '.srt-settings.json')
const configData = readFileSync(configPath, 'utf-8')
const config: SandboxRuntimeConfig = JSON.parse(configData)
console.log('Initializing sandbox with config:', JSON.stringify(config, null, 2))
// Initialize the sandbox (starts proxy servers, etc.)
await SandboxManager.initialize(config)
console.log('Sandbox initialized successfully')
// The command to run
const command = 'npx -y @github/copilot@0.0.347 -p "whats 2+2"'
// Wrap the command with sandbox restrictions
const sandboxedCommand = await SandboxManager.wrapWithSandbox(command)
console.log(`Executing sandboxed command: ${sandboxedCommand}`)
// Execute the sandboxed command
const child = spawn(sandboxedCommand, {
shell: true,
stdio: 'inherit',
env: {
...process.env,
GITHUB_TOKEN: process.env.GITHUB_TOKEN || '',
NO_COLOR: '1',
TERM: 'dumb'
}
})
// Handle exit
child.on('exit', async (code) => {
console.log(`\nCommand exited with code ${code}`)
// Cleanup when done
await SandboxManager.reset()
console.log('Sandbox cleaned up')
process.exit(code || 0)
})
// Handle errors
child.on('error', async (err) => {
console.error('Error executing command:', err)
await SandboxManager.reset()
process.exit(1)
})
}
// Run the main function
main().catch(async (err) => {
console.error('Fatal error:', err)
await SandboxManager.reset()
process.exit(1)
})