> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firecrawl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# セッションでのコード実行

> スタンドアロンのInteractセッションで、Playwrightまたはagent-browserのコードを実行します。

<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 theme={null}
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 theme={null}
{
  "success": true,
  "result": "Example Domain"
}
```

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

```json theme={null}
{
  "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)を参照してください。


## OpenAPI

````yaml ja/api-reference/v2-openapi.json POST /interact/{sessionId}/execute
openapi: 3.0.0
info:
  contact:
    email: support@firecrawl.dev
    name: Firecrawl Support
    url: https://firecrawl.dev/support
  description: Firecrawlのサービスを利用して、Webスクレイピングやクロールを行うためのAPIです。
  title: Firecrawl API
  version: v2
servers:
  - url: https://api.firecrawl.dev/v2
security:
  - bearerAuth: []
paths:
  /interact/{sessionId}/execute:
    post:
      tags:
        - Interact
      summary: Interactセッションでコードを実行
      operationId: executeBrowserCode
      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: 支払いが必要です
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      scheme: bearer
      type: http

````