Closed as duplicate
Description
When running JS code in the Sandbox, the top level promise is never awaited:
import { Sandbox } from '@e2b/code-interpreter'
const sandbox = await Sandbox.create({apiKey: ''})
const code = `
const printResult = async () => {
return 'foo';
};
printResult()
.then((result) => {
console.log("glama.result");
})
.catch((error) => {
console.log("glama.error");
});
`
console.log('running code')
const ex = await sandbox.runCode(code, {
language: 'js',
onError: (error) => {
console.log('error', error)
},
onStdout: (stdout) => {
console.log('stdout', stdout)
},
onStderr: (stderr) => {
console.log('stderr', stderr)
},
})
console.log('code executed', ex)
The code above will produce a following output
running code
code executed Execution {
results: [
Result {
isMainResult: true,
text: 'Promise { <pending> }',
html: undefined,
markdown: undefined,
svg: undefined,
png: undefined,
jpeg: undefined,
pdf: undefined,
latex: undefined,
json: undefined,
javascript: undefined,
raw: [Object],
data: undefined,
chart: undefined,
extra: {}
}
],
logs: { stdout: [], stderr: [] },
error: undefined,
executionCount: 2
}
The text
field says 'Promise { <pending> }'
which means the promise was never awaited.