Clear sandbox execution result cache to free memory and reset cache statistics in HopX sandboxes. Remove cached execution results to free resources, force re-execution of code, or reset cache performance metrics. Essential for memory management and debugging. Includes Python and JavaScript SDK examples and REST API endpoints.
Clear the execution result cache to free memory, reset cache statistics, and ensure fresh executions for testing or debugging.
Clear cache before running tests to ensure fresh executions:
Python
JavaScript
from hopx_ai import Sandboxsandbox = Sandbox.create(template="code-interpreter")# Clear cache before testingprint("Clearing cache for fresh test execution...")sandbox.cache.clear()# Run test code (will be cache miss)result = sandbox.run_code("""import timestart = time.time()# Simulate some computationsum(range(100000))end = time.time()print(f"Execution time: {end - start:.3f}s")""")print("Test completed with fresh execution")sandbox.kill()
import { Sandbox } from '@hopx-ai/sdk';const sandbox = await Sandbox.create({ template: 'code-interpreter'});// Clear cache before testingconsole.log('Clearing cache for fresh test execution...');await sandbox.cache.clear();// Run test code (will be cache miss)const result = await sandbox.runCode(`import timestart = time.time()# Simulate some computationsum(range(100000))end = time.time()print(f"Execution time: {end - start:.3f}s")`);console.log('Test completed with fresh execution');await sandbox.kill();