Metadata lets you label Sandboxes in the control plane so your application can track tasks, users, scenarios, and versions. Metadata does not automatically become environment variables inside the Sandbox.
Write Metadata When Creating a Sandbox
const sandbox = await Sandbox.create("code-interpreter-v1", {
apiKey: process.env.E2B_API_KEY,
apiUrl: process.env.E2B_API_URL,
domain: process.env.E2B_DOMAIN,
metadata: {
task_id: "task-001",
agent: "code-reviewer",
},
});
const info = await sandbox.getInfo();
console.log(info.metadata);Python example:
sandbox = Sandbox.create(
template="code-interpreter-v1",
api_key=os.environ["E2B_API_KEY"],
api_url=os.environ["E2B_API_URL"],
domain=os.environ["E2B_DOMAIN"],
metadata={
"task_id": "task-001",
"agent": "code-reviewer",
},
)
info = sandbox.get_info()
print(info.metadata)Metadata vs. environment variables
Metadata is used for management-plane queries, audit, and business correlation.
Environment variables are read by processes inside the Sandbox.
If the same business field must be visible in both the management plane and the process runtime, write it to both
metadataandenvs.
Recommendations
Keep metadata values short strings whenever possible. Do not store large context blocks, user privacy data, or credentials in metadata. Complex business state should live in your application database, while metadata should keep only indexable correlation IDs.