# セッションでのコード実行 (/ja/api-reference/endpoint/browser-execute)

<!-- agent-signals: reading_time_min: 2 · est_tokens: 1292 · updated: 2026-07-30 -->
Related: [検索](/ja/api-reference/endpoint/search.md), [検索フィードバック](/ja/api-reference/endpoint/search-feedback.md), [スクレイプ](/ja/api-reference/endpoint/scrape.md), [バッチスクレープ](/ja/api-reference/endpoint/batch-scrape.md), [バッチスクレイプのステータス取得](/ja/api-reference/endpoint/batch-scrape-get.md), [バッチスクレイプのキャンセル](/ja/api-reference/endpoint/batch-scrape-delete.md)

<div id="headers">
  ## ヘッダー [#ヘッダー]
</div>

| ヘッダー            | 値                  |
| --------------- | ------------------ |
| `Authorization` | `Bearer <API_KEY>` |
| `Content-Type`  | `application/json` |

<div id="request-body">
  ## リクエストボディ [#リクエストボディ]
</div>

| パラメータ      | 型      | 必須  | デフォルト    | 説明                                                               |
| ---------- | ------ | --- | -------- | ---------------------------------------------------------------- |
| `code`     | string | はい  | -        | 実行するコード（1〜100,000 文字）                                            |
| `language` | string | いいえ | `"node"` | コードの言語：`"python"`、`"node"`、または `"bash"`（agent-browser CLI コマンド用） |
| `timeout`  | number | いいえ | -        | 実行タイムアウト時間（秒、1〜300）                                              |

<div id="response">
  ## レスポンス [#レスポンス]
</div>

| Field      | Type    | Description                   |
| ---------- | ------- | ----------------------------- |
| `success`  | boolean | コードが正常に実行されたかどうか              |
| `stdout`   | string  | コード実行時の標準出力                   |
| `result`   | string  | コード実行時の標準出力                   |
| `stderr`   | string  | コード実行時の標準エラー出力                |
| `exitCode` | number  | 実行されたプロセスの終了コード               |
| `killed`   | boolean | プロセスがタイムアウトにより強制終了されたかどうか     |
| `error`    | string  | 実行が失敗した場合のエラーメッセージ（失敗時のみ含まれる） |

<div id="example-request">
  ### リクエスト例 [#リクエスト例]
</div>

```bash
curl -X POST "https://api.firecrawl.dev/v2/interact/550e8400-e29b-41d4-a716-446655440000/execute" \
  -H "Authorization: Bearer $FIRECRAWL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "await page.goto(\"https://example.com\")\ntitle = await page.title()\nprint(title)",
    "language": "python"
  }'
```

<div id="example-response-success">
  ### 成功時のレスポンス例 [#成功時のレスポンス例]
</div>

```json
{
  "success": true,
  "result": "Example Domain"
}
```

<div id="example-response-error">
  ### エラー時のレスポンス例 [#エラー時のレスポンス例]
</div>

```json
{
  "success": true,
  "error": "TimeoutError: page.goto: Timeout 30000ms exceeded."
}
```

> Firecrawl API key が必要な AI agent ですか？自動オンボーディングの手順については、[firecrawl.dev/agent-onboarding/SKILL.md](https://www.firecrawl.dev/agent-onboarding/SKILL.md)を参照してください。

`POST /interact/{sessionId}/execute`

Interactセッションでコードを実行

## OpenAPI

```json
{
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "parameters": [
    {
      "description": "InteractセッションID",
      "in": "path",
      "name": "sessionId",
      "required": true,
      "schema": {
        "type": "string"
      }
    }
  ],
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "properties": {
            "code": {
              "description": "ブラウザサンドボックスで実行するコード",
              "maxLength": 100000,
              "minLength": 1,
              "type": "string"
            },
            "language": {
              "default": "node",
              "description": "実行するコードの言語。JavaScript には `node`、agent-browser CLI コマンドには `bash` を使用します。",
              "enum": [
                "python",
                "node",
                "bash"
              ],
              "type": "string"
            },
            "timeout": {
              "description": "実行タイムアウト（秒）",
              "maximum": 300,
              "minimum": 1,
              "type": "integer"
            }
          },
          "required": [
            "code"
          ],
          "type": "object"
        }
      }
    },
    "required": true
  },
  "responses": {
    "200": {
      "content": {
        "application/json": {
          "schema": {
            "properties": {
              "error": {
                "description": "コードで例外が発生した場合のエラーメッセージ",
                "nullable": true,
                "type": "string"
              },
              "exitCode": {
                "description": "実行されたプロセスの終了コード",
                "nullable": true,
                "type": "integer"
              },
              "killed": {
                "description": "プロセスがタイムアウトにより強制終了されたかどうか",
                "type": "boolean"
              },
              "result": {
                "description": "標準出力（stdout の別名）",
                "nullable": true,
                "type": "string"
              },
              "stderr": {
                "description": "コード実行時の標準エラー出力",
                "nullable": true,
                "type": "string"
              },
              "stdout": {
                "description": "コード実行時の標準出力",
                "nullable": true,
                "type": "string"
              },
              "success": {
                "type": "boolean"
              }
            },
            "type": "object"
          }
        }
      },
      "description": "コードが正常に実行されました"
    },
    "402": {
      "content": {
        "application/json": {
          "schema": {
            "properties": {
              "error": {
                "example": "Payment required to access this resource.",
                "type": "string"
              }
            },
            "type": "object"
          }
        }
      },
      "description": "支払いが必要です"
    }
  }
}
```
