import { Sandbox } from '@e2b/code-interpreter'
import fs from 'fs'
const codeToRun = `
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()
`
const sandbox = await Sandbox.create()
// Run the code inside the sandbox
const execution = await sandbox.runCode(codeToRun)
// There's only one result in this case - the plot displayed with `plt.show()`
const firstResult = execution.results[0]
if (firstResult.png) {
// Save the png to a file. The png is in base64 format.
fs.writeFileSync('chart.png', firstResult.png, { encoding: 'base64' })
console.log('Chart saved as chart.png')
}