Appearance
Sandbox Metadata
Metadata allows you to attach custom key-value pairs when creating a sandbox. Use it to associate user sessions, store configuration information, or tag sandbox purposes.
Setting Metadata
Set metadata via the metadata parameter when creating a sandbox.
javascript
import { Sandbox } from '@e2b/code-interpreter'
async function main() {
const sandbox = await Sandbox.create({
metadata: {
userId: '123',
},
})
await sandbox.kill()
}
main()Reading Metadata
When retrieving a list of sandboxes with Sandbox.list(), you can access each sandbox's metadata.
javascript
import { Sandbox } from '@e2b/code-interpreter'
async function main() {
const paginator = await Sandbox.list()
const runningSandboxes = await paginator.nextItems()
if (runningSandboxes.length > 0) {
console.log(runningSandboxes[0].metadata)
}
}
main()Filtering by Metadata
For details on filtering the sandbox list using metadata fields, see the Sandbox List documentation.