メインコンテンツへスキップ

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 解析を実行します。同梱の xai Plugin(tools コントラクト配下)によって登録され、x_search が使用するものと同じ https://api.x.ai/v1/responses エンドポイントにディスパッチします。
プロパティ
ツール名code_execution
プロバイダーPluginxai(同梱、enabledByDefault: true
認証xAI 認証プロファイル、XAI_API_KEY、または plugins.entries.xai.config.webSearch.apiKey
既定のモデルgrok-4-1-fast
既定のタイムアウト30 秒
既定の maxTurns未設定(xAI が独自の内部制限を適用)
これはローカルの exec とは異なります。
  • exec は、自分のマシンまたはペアリングされたノードでシェルコマンドを実行します。
  • code_execution は、xAI のリモートサンドボックスで Python を実行します。
code_execution は次の用途に使います。
  • 計算。
  • 表形式化。
  • 簡単な統計。
  • グラフ形式の解析。
  • x_search または web_search から返されたデータの解析。
ローカルファイル、シェル、リポジトリ、またはペアリングされたデバイスが必要な場合は使用しないでください。その場合は exec を使います。

セットアップ

1

xAI API キーを指定する

code_executionx_search 用に openclaw onboard --auth-choice xai-api-key を実行するか、 Grok Web 検索でも同じ認証情報を使いたい場合は XAI_API_KEY を設定するか、 xAI Plugin 配下でキーを構成します。
export XAI_API_KEY=xai-...
または設定経由:
{
  plugins: {
    entries: {
      xai: {
        config: {
          webSearch: {
            apiKey: "xai-...",
          },
        },
      },
    },
  },
}
2

code_execution を有効化して調整する

このツールは plugins.entries.xai.config.codeExecution.enabled で制御されます。既定ではオフです。
{
  plugins: {
    entries: {
      xai: {
        config: {
          codeExecution: {
            enabled: true,
            model: "grok-4-1-fast", // 既定の xAI コード実行モデルを上書き
            maxTurns: 2,            // 内部ツールターンの任意の上限
            timeoutSeconds: 30,     // リクエストタイムアウト(既定: 30)
          },
        },
      },
    },
  },
}
3

Gateway を再起動する

openclaw gateway restart
xAI Plugin が enabled: true で再登録されると、code_execution がエージェントのツール一覧に表示されます。

使い方

自然に依頼し、解析の意図を明確にします。
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 パラメーターを受け取るため、エージェントは完全な解析リクエストとインラインデータを 1 つのプロンプトで送る必要があります。

エラー

ツールが認証なしで実行されると、認証プロファイル、環境変数、設定オプションを指す構造化された missing_xai_api_key エラーを返します。このエラーは JSON であり、スローされた例外ではないため、エージェントは自己修正できます。
{
  "error": "missing_xai_api_key",
  "message": "code_execution needs an xAI API key. Run openclaw onboard --auth-choice xai-api-key, set XAI_API_KEY in the Gateway environment, or configure plugins.entries.xai.config.webSearch.apiKey.",
  "docs": "https://docs.openclaw.ai/tools/code-execution"
}

制限

  • これはリモートの xAI 実行であり、ローカルプロセス実行ではありません。
  • 結果は永続的なノートブックセッションではなく、一時的な解析として扱ってください。
  • ローカルファイルやワークスペースへのアクセスを前提にしないでください。
  • 新しい X データについては、まず x_search を使い、その結果を code_execution に渡してください。

関連

Exec ツール

自分のマシンまたはペアリングされたノードでのローカルシェル実行。

Exec 承認

シェル実行の許可/拒否ポリシー。

Web ツール

web_searchx_searchweb_fetch

xAI プロバイダー

Grok モデル、Web/X 検索、コード実行設定。