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

> スタンドアロンの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
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)を参照してください。
