View Source Anthropic.Tools.CodeExecution (anthropic_community v0.5.0)

Builds the code execution 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."}]
)

Summary

Functions

Options

  • :version (String.t/0) - The tool's versioned type string. Override to pin an older API version. The default value is "code_execution_20260521".

Functions

@spec new(keyword()) :: map()

Options

  • :version (String.t/0) - The tool's versioned type string. Override to pin an older API version. The default value is "code_execution_20260521".

  • :cache_control (map/0) - An Anthropic.CacheControl map.