Method signature
Parameters
This method takes no parameters.Return value
Type | Description |
---|---|
Promise<void> | The method completes successfully when the sandbox is terminated |
Behavior
Thekill()
method performs the following actions:
- Agent Type Validation: Verifies that the current agent is of type “codex”
- Initialization Check: Ensures the CodexAgent instance is properly initialized
- Sandbox Termination: Calls the underlying
killSandbox()
method to terminate the active sandbox
Examples
Basic Usage
With Error Handling
Cleanup Pattern
Error handling
The method throws errors in the following cases:Agent Type Error
Initialization Error
Example Error Handling
Use cases
Resource Management
Perfect for cleaning up sandbox resources when your application is done with code generation:Error Recovery
Use in error handling to ensure sandbox cleanup:Notes
- Resource Cleanup: Always call
kill()
when you’re done with sandbox operations to free up resources - State Reset: Killing a sandbox destroys all its state and files
- Irreversible: Once killed, the sandbox cannot be resumed - you’ll need to generate new code to create a fresh sandbox
- Best Practice: Use in cleanup routines and error handlers to prevent resource leaks