跳轉到主要內容

Documentation Index

Fetch the complete documentation index at: https://docs.openclaw.ai/llms.txt

Use this file to discover all available pages before exploring further.

code_execution 會在 xAI 的 Responses API 上執行沙盒化的遠端 Python 分析。 這與本機 exec 不同:
  • exec 會在你的機器或節點上執行 shell 命令
  • code_execution 會在 xAI 的遠端沙盒中執行 Python
使用 code_execution 來進行:
  • 計算
  • 製表
  • 快速統計
  • 圖表式分析
  • 分析由 x_searchweb_search 傳回的資料
當你需要本機檔案、你的 shell、你的儲存庫或配對裝置時,不要使用它。請改用 exec

設定

你需要 xAI API 金鑰。以下任一種都可以:
  • XAI_API_KEY
  • plugins.entries.xai.config.webSearch.apiKey
範例:
{
  plugins: {
    entries: {
      xai: {
        config: {
          webSearch: {
            apiKey: "xai-...",
          },
          codeExecution: {
            enabled: true,
            model: "grok-4-1-fast",
            maxTurns: 2,
            timeoutSeconds: 30,
          },
        },
      },
    },
  },
}

如何使用

自然地提出要求,並明確說明分析意圖:
Use code_execution to calculate the 7-day moving average for these numbers: ...
Use x_search to find posts mentioning OpenClaw this week, then use code_execution to count them by day.
Use web_search to gather the latest AI benchmark numbers, then use code_execution to compare percent changes.
此工具在內部接受單一 task 參數,因此 agent 應在一個提示中送出完整的分析要求與任何內嵌資料。

限制

  • 這是遠端 xAI 執行,不是本機程序執行。
  • 它應被視為臨時分析,而不是持久化筆記本。
  • 不要假設可存取本機檔案或你的工作區。
  • 若要取得最新 X 資料,請先使用 x_search

相關