

# Resource management
<a name="code-interpreter-resource-management"></a>

The AgentCore Code Interpreter provides two types of resources:

System ARNs  
System ARNs are default resources pre-created for ease of use. These ARNs have default configuration with the most restrictive options and are available for all regions where Amazon Bedrock AgentCore is available.      
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/code-interpreter-resource-management.html)

Custom ARNs  
Custom ARNs allow you to configure a code interpreter with your own settings. You can choose network settings (Sandbox or Public), and the execution role that defines what AWS resources the code interpreter can access.

**Topics**
+ [Network settings](#code-interpreter-network-settings)
+ [Creating an AgentCore Code Interpreter](code-interpreter-create.md)
+ [Listing AgentCore Code Interpreter tools](code-interpreter-list.md)
+ [Deleting an AgentCore Code Interpreter](code-interpreter-delete.md)

## Network settings
<a name="code-interpreter-network-settings"></a>

The AgentCore Code Interpreter supports the following network modes:

Sandbox mode  
Provides limited external network access. In Sandbox mode, the code interpreter can access Amazon S3 for data operations and perform DNS resolution.

Public network mode  
Allows the tool to access public internet resources. This option enables integration with external APIs and services but introduces potential security considerations.

VPC mode  
Connects the tool to your Virtual Private Cloud (VPC), allowing access to private resources within your AWS environment such as databases, internal APIs, and other services while maintaining network isolation from the public internet. This option requires additional VPC configuration.

The following topics show you how to create and manage Code Interpreters, start and stop sessions, and how to execute code.

# Creating an AgentCore Code Interpreter
<a name="code-interpreter-create"></a>

You can create a Code Interpreter using the Amazon Bedrock AgentCore console, AWS CLI, or AWS SDK.

**Example**  

1. ====== To create a Code Interpreter using the console

1. Open the AgentCore console at [https://console.aws.amazon.com/bedrock-agentcore/home\$1](https://console.aws.amazon.com/bedrock-agentcore/home#).

1. In the navigation pane, choose **Built-in tools**.

1. Choose **Create Code Interpreter tool**.

1. Provide a unique **Tool name** and optional **Description**.

1. Under **Network settings** , choose one of the following options:
   +  **Sandbox** - Environment with limited external network access
   +  **Public network** - Allows access to public internet resources

1. Under **Permissions** , specify an IAM runtime role that defines what AWS resources the Code Interpreter can access.

1. Choose **Create**.

   After creating a Code Interpreter tool, the console displays important details about the tool:
The Amazon Resource Name (ARN) that uniquely identifies the Code Interpreter tool resource (e.g., arn:aws:bedrock-agentcore:<Region>:123456789012:code-interpreter/code-interpreter-custom).
The unique identifier for the Code Interpreter tool, used in API calls (e.g., code-interpreter-custom-abc123).
The IAM role that the Code Interpreter assumes when executing code, determining what AWS resources it can access.
The network configuration for the Code Interpreter (Sandbox or Public).
The date and time when the Code Interpreter tool was created.

1. To create a Code Interpreter using the AWS CLI, use the `create-code-interpreter` command:

   ```
   aws bedrock-agentcore create-code-interpreter \
     --region <Region> \
     --name "my-code-interpreter" \
     --description "My Code Interpreter for data analysis" \
     --network-configuration '{
       "networkMode": "PUBLIC"
     }' \
     --execution-role-arn "arn:aws:iam::123456789012:role/my-execution-role"
   ```

1. To create a Code Interpreter using the AWS SDK for Python, use the `create_code_interpreter` method:

   ```
   import boto3
   
   # Initialize the boto3 client
   cp_client = boto3.client(
       'bedrock-agentcore-control',
       region_name="<Region>",
       endpoint_url="https://bedrock-agentcore-control.<Region>.amazonaws.com"
   )
   
   # Create a Code Interpreter
   response = cp_client.create_code_interpreter(
       name="myTestSandbox1",
       description="Test code sandbox for development",
       executionRoleArn="arn:aws:iam::123456789012:role/my-execution-role",
       networkConfiguration={
           "networkMode": "PUBLIC"
       }
   )
   
   # Print the Code Interpreter ID
   code_interpreter_id = response["codeInterpreterId"]
   print(f"Code Interpreter ID: {code_interpreter_id}")
   ```

1. To create a new Code Interpreter instance using the API, use the following call:

   ```
   # Using awscurl
   awscurl -X PUT "https://bedrock-agentcore-control.<Region>.amazonaws.com/code-interpreters" \
   -H "Content-Type: application/json" \
   --region <Region> \
   --service bedrock-agentcore \
   -d '{
       "name": "codeinterpreter'$(date +%m%d%H%M%S)'",
       "description": "Test code sandbox for development",
       "executionRoleArn": "'${ROLE_ARN}'",
       "networkConfiguration": {
           "networkMode": "PUBLIC"
       }
   }'
   ```

# Listing AgentCore Code Interpreter tools
<a name="code-interpreter-list"></a>

You can view a list of all your Code Interpreter tools to manage and monitor them.

**Example**  

1. ====== To list code interpreters using the console

1. Open the AgentCore console at [https://console.aws.amazon.com/bedrock-agentcore/home\$1](https://console.aws.amazon.com/bedrock-agentcore/home#).

1. In the navigation pane, choose **Built-in tools**.

1. The console displays a list of all your Code Interpreter tools, including their names, IDs, creation dates, and status.

1. You can use the search box to filter the list by name or other attributes.

1. Select a Code Interpreter to view its details, including active sessions and configuration settings.

1. To list Code Interpreters using the AWS CLI, use the `list-code-interpreters` command:

   ```
   aws bedrock-agentcore list-code-interpreters \
     --region <Region> \
     --max-results 10
   ```

   You can use the `--next-token` parameter for pagination if you have more than the maximum results:

   ```
   aws bedrock-agentcore list-code-interpreters \
     --region <Region> \
     --max-results 10 \
     --next-token "<your-pagination-token>"
   ```

1. To list Code Interpreters using the AWS SDK for Python, use the `list_code_interpreters` method:

   ```
   import boto3
   
   # Initialize the boto3 client
   cp_client = boto3.client(
       'bedrock-agentcore-control',
       region_name="<Region>",
       endpoint_url="https://bedrock-agentcore-control.<Region>.amazonaws.com"
   )
   
   # List Code Interpreters
   response = cp_client.list_code_interpreters()
   
   # Print the Code Interpreters
   for interpreter in response.get('codeInterpreterSummaries', []):
       print(f"Name: {interpreter.get('name')}")
       print(f"ID: {interpreter.get('codeInterpreterId')}")
       print(f"Creation Time: {interpreter.get('createdAt')}")
       print(f"Status: {interpreter.get('status')}")
       print("---")
   
   # If there are more results, get the next page using the next_token
   if 'nextToken' in response:
       next_page = cp_client.list_code_interpreters(
           nextToken=response['nextToken']
       )
       # Process next_page...
   ```

1. To list Code Interpreter instances using the API, use the following call:
**Note**  
For pagination, include the nextToken parameter.

   ```
   # Using awscurl
   awscurl -X POST "https://bedrock-agentcore-control.<Region>.amazonaws.com/code-interpreters" \
     -H "Accept: application/json" \
     --service bedrock-agentcore \
     --region <Region>
   ```

# Deleting an AgentCore Code Interpreter
<a name="code-interpreter-delete"></a>

When you no longer need a Code Interpreter, you can delete it to free up resources and avoid unnecessary charges.

**Important**  
Deleting a Code Interpreter permanently removes it and all its configuration. This action cannot be undone. Make sure all active sessions are stopped before deleting a Code Interpreter.

**Example**  

1. ====== To delete a Code Interpreter using the console

1. Open the AgentCore console at [https://console.aws.amazon.com/bedrock-agentcore/home\$1](https://console.aws.amazon.com/bedrock-agentcore/home#).

1. In the navigation pane, choose **Built-in tools**.

1. From the list of code interpreter tools, select the tool you want to delete.

1. Choose **Delete**.

1. In the confirmation dialog, enter the name of the code interpreter to confirm deletion.

1. Choose **Delete** to permanently delete the Code Interpreter.

1. To delete a Code Interpreter using the AWS CLI, use the `delete-code-interpreter` command:

   ```
   aws bedrock-agentcore delete-code-interpreter \
     --region <Region> \
     --code-interpreter-id "<your-code-interpreter-id>"
   ```

1. To delete a Code Interpreter using the AWS SDK for Python, use the `delete_code_interpreter` method:

   ```
   import boto3
   
   # Initialize the boto3 client
   cp_client = boto3.client(
       'bedrock-agentcore-control',
       region_name="<Region>",
       endpoint_url="https://bedrock-agentcore-control.<Region>.amazonaws.com"
   )
   
   # Delete a Code Interpreter
   response = cp_client.delete_code_interpreter(
       codeInterpreterId="<your-code-interpreter-id>"
   )
   
   print("Code Interpreter deleted successfully")
   ```

1. To delete a Code Interpreter instance using the API, use the following call:

   ```
   # Using awscurl
   awscurl -X DELETE "https://bedrock-agentcore-control.<Region>.amazonaws.com/code-interpreters/<your-code-interpreter-id>" \
   -H "Accept: application/json" \
   --service bedrock-agentcore \
   --region <Region>
   ```