mirror of
https://github.com/anthropic-experimental/sandbox-runtime.git
synced 2026-05-07 06:01:25 +08:00
Fix README example: move reset() inside exit callback (#54)
The previous example called reset() immediately after spawning the child process, which would shut down proxy servers before the child process completes. This caused the sandboxed command to fail. Move reset() inside the 'exit' event callback to ensure cleanup happens after the child process terminates.
This commit is contained in:
@@ -203,13 +203,12 @@ const sandboxedCommand = await SandboxManager.wrapWithSandbox(
|
||||
// Execute the sandboxed command
|
||||
const child = spawn(sandboxedCommand, { shell: true, stdio: 'inherit' })
|
||||
|
||||
// Handle exit
|
||||
child.on('exit', code => {
|
||||
// Handle exit and cleanup after child process completes
|
||||
child.on('exit', async code => {
|
||||
console.log(`Command exited with code ${code}`)
|
||||
// Cleanup when done (optional, happens automatically on process exit)
|
||||
await SandboxManager.reset()
|
||||
})
|
||||
|
||||
// Cleanup when done (optional, happens automatically on process exit)
|
||||
await SandboxManager.reset()
|
||||
```
|
||||
|
||||
#### Available exports
|
||||
|
||||
Reference in New Issue
Block a user