全部產品
Search
文件中心

Function Compute:中繼資料

更新時間:Jul 22, 2026

中繼資料用於在控制面標記沙箱,便於業務系統追蹤任務、使用者、情境和版本。中繼資料不會自動變成沙箱內的環境變數。

建立沙箱時寫入中繼資料

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 樣本:

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 和 envs。

使用建議

中繼資料值建議使用短字串,避免寫入大段上下文、使用者隱私或憑證。複雜業務狀態應儲存在業務資料庫中,中繼資料只儲存可索引的關聯 ID。