defmodule Anthropic.Tools.CodeExecution do @moduledoc """ Builds the [code execution](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool) server tool definition. Pass the result inside the `:tools` list to `Anthropic.Messages.create/2` — Claude runs code server-side in a sandbox and the result comes back as a `%Anthropic.Messages.Content.CodeExecutionToolResult{}` block; no client-side `execute/1` needed. ## Examples Anthropic.Messages.create(client, model: "claude-opus-4-8", max_tokens: 1024, tools: [Anthropic.Tools.CodeExecution.new()], messages: [%{role: "user", content: "Compute the 30th Fibonacci number."}] ) """ @latest_version "code_execution_20260521" @schema NimbleOptions.new!( version: [ type: :string, default: @latest_version, doc: "The tool's versioned `type` string. Override to pin an older API version." ], cache_control: [type: :map, doc: "An `Anthropic.CacheControl` map."] ) @doc """ ## Options #{NimbleOptions.docs(@schema)} """ @spec new(keyword()) :: map() def new(opts \\ []) do opts = NimbleOptions.validate!(opts, @schema) {version, opts} = Keyword.pop!(opts, :version) Anthropic.Tools.ServerTool.build(%{type: version, name: "code_execution"}, opts) end end