---
title: "Execute Code Snippet"
method: POST
path: "/v1/tools/execute-code"
tags: ["Tools"]
---

# Execute Code Snippet

`POST /v1/tools/execute-code`

## Request

- Base URL: `https://api.anchorbrowser.io`
- URL: `https://api.anchorbrowser.io/v1/tools/execute-code`
- Auth: API key in header `anchor-api-key`

Run a TypeScript snippet in the sandbox against the browser session (query `sessionId` required).

## Query parameters

- `sessionId` string, uuid, required

## Request body

- ExecuteCodeRequestSchema
  - `code` string, required: TypeScript snippet (async function body) with injected page, browser, context, sessionId, anchorClient.

## Response `200`

Snippet execution finished.

- ExecuteCodeToolResponseSchema
  - `success` boolean, required
  - `message` string, required
  - `output` string: JSON string of the return value when execution succeeds.
  - `error` string
  - `executionResultId` string, uuid

## Other responses

- `400`: Invalid request.
- `500`: Internal server error.

## Changes

- **2026-10-16** `b3bfdb98c79e`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/anchorbrowser/apis/anchorbrowser-api/changes/v1/tools/execute-code/post.md)

---

[API](https://skmtc.dev/anchorbrowser/apis/anchorbrowser-api.md) - [All operations](https://skmtc.dev/anchorbrowser/apis/anchorbrowser-api/llms.txt) - [OpenAPI document](https://skmtc.dev/anchorbrowser/apis/anchorbrowser-api/revisions/9d755f22df0e?raw)
