Built-in tool that enables Claude to execute code in a sandboxed environment.
Value
A tool specification list for use with claude_new().
Details
Requires beta header: Use beta = beta_headers$BETA_CODE_EXEC_BASH with claude_new().
Bash environment (type = "bash"):
Supports Bash commands and file operations
Beta:
code-execution-2025-08-25Tool type:
code_execution_20250825
Python environment (type = "python"):
Sandboxed Python execution
Can process files uploaded via Files API
Beta:
code-execution-2025-05-22Tool type:
code_execution_20250522
Note: Code execution is a server-side tool handled by Anthropic's infrastructure. Results are returned directly in Claude's response.
Examples
if (FALSE) { # \dontrun{
# Bash code execution
chat <- claude_new(
tools = list(claude_code_exec()),
beta = beta_headers$BETA_CODE_EXEC_BASH
)
chat$chat("Calculate the first 20 Fibonacci numbers")
# Python code execution
chat <- claude_new(
tools = list(claude_code_exec(type = "python")),
beta = beta_headers$BETA_CODE_EXEC_PYTHON
)
chat$chat("Create a scatter plot of random data")
} # }
