# CodeInterpreterToolResource Methods

- Package: [Aspire.Hosting.Foundry](/reference/api/csharp/aspire.hosting.foundry.md)
- Type: [CodeInterpreterToolResource](/reference/api/csharp/aspire.hosting.foundry/codeinterpretertoolresource.md)
- Kind: `Methods`
- Members: `1`

A Foundry tool resource that enables an agent to write and run Python code in a sandboxed environment for data analysis, math, and chart generation.

## ToAgentToolAsync(CancellationToken)

- Name: `ToAgentToolAsync(CancellationToken)`
- Modifiers: `override`
- Returns: `Task<ResponseTool>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Foundry/ToolResources/BuiltInToolDefinitions.cs#L33-L34)

Converts this tool definition into the SDK `Responses.ResponseTool` representation.

```csharp
public sealed class CodeInterpreterToolResource
{
    public override Task<ResponseTool> ToAgentToolAsync(
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `cancellationToken` (`CancellationToken`) `optional`
  A cancellation token.

## Returns

`Task<ResponseTool>` -- The SDK tool representation.

## Remarks

This method is called at deploy time, after infrastructure provisioning is complete. Tools that depend on provisioned resources (e.g., Azure AI Search connections) can safely resolve their connection identifiers at this point.
