Skip to main content

Method signature

Parameters

This method takes no parameters.

Return value

Behavior

The kill() method performs the following actions:
  1. Agent Type Validation: Verifies that the current agent is of type “codex”
  2. Initialization Check: Ensures the CodexAgent instance is properly initialized
  3. 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