The following example demonstrates how to create a shared context between multiple code executions. This is useful when you want to share variables between different code cells.
import { CodeInterpreter } from '@e2b/code-interpreter'const sandbox = await CodeInterpreter.create()const code = `import matplotlib.pyplot as pltimport numpy as npx = np.linspace(0, 20, 100)y = np.sin(x)plt.plot(x, y)plt.show()`;// you can install dependencies in "jupyter notebook style"await sandbox.notebook.execCell("!pip install matplotlib")const execution = await sandbox.notebook.execCell(code)// this contains the image data, you can e.g. save it to file or send to frontendexecution.results[0].pngawait sandbox.close()