Amazon Bedrock Code Interpreter connector
Use the Amazon Bedrock Code Interpreter connector to execute code in a secure Amazon Bedrock AgentCore Code Interpreter sandbox from your BPMN process.
About this connector
The Amazon Bedrock Code Interpreter connector is an outbound connector. It starts a sandbox session, runs the Python, JavaScript, or TypeScript code you provide, and returns the output and any files generated by the code as Camunda documents. The session is stopped when the code has run.
Prerequisites
To use the Amazon Bedrock Code Interpreter connector, you need the following:
- An AWS account with an access key and secret key, a configured default credentials chain (hybrid/Self-Managed only), or a saved AWS credential.
- IAM permissions to execute the following actions on the
bedrock-agentcoreservice:StartCodeInterpreterSessionInvokeCodeInterpreterStopCodeInterpreterSession
- The AgentCore Code Interpreter service must be available in your selected AWS region.
Learn more about the AgentCore Code Interpreter in the official documentation.
Use secrets to store credentials and avoid exposing sensitive information from the process. See managing secrets.
Use this connector
New to using an outbound connector? Learn how to add and use this type of connector, apply element templates, use connector secrets, handle results and errors, and more.
Configuration
Authentication
| Property | Type | Required | Description | Example |
|---|---|---|---|---|
| AWS credential | Configuration | No | Select a saved AWS credential with an optional default region, or enter the authentication details and a region in the fields below. Learn more about credentials. | |
| Authentication | Dropdown | Yes, if no AWS credential is set | The AWS authentication strategy:
| |
| Access key | String | Yes, if Authentication is Credentials | The access key of an IAM user with the necessary permissions for this connector. | |
| Secret key | String | Yes, if Authentication is Credentials | The secret key of the IAM user with the access key above. |
For more information on authentication and security in Amazon Bedrock, see Amazon Bedrock security and privacy.
Region
| Property | Type | Required | Description | Example |
|---|---|---|---|---|
| Region | String | Yes, if no AWS credential is set | The AWS region where Amazon Bedrock AgentCore Code Interpreter is available. | us-east-1 |
| Region | String | Yes, if the credential has no default region | Overrides the default region of the selected AWS credential. Shown when an AWS credential is selected. Required when the credential has no default region. |
Operations
The connector has a single operation, which runs code in the sandbox.
Run code
Execute code in an Amazon Bedrock AgentCore Code Interpreter sandbox session.
Input parameters
| Property | Type | Required | Description | Example |
|---|---|---|---|---|
| Language | Dropdown | Yes | The programming language of the code: Python, JavaScript, or TypeScript. | |
| Code | String | Yes | The code to execute in the Code Interpreter sandbox. Supports FEEL expressions. | |
| Code Interpreter ID | String | No | The identifier of the Code Interpreter to use. The default is aws.codeinterpreter.v1, the AWS managed default. | |
| Session timeout | String | No | The session timeout as an ISO 8601 duration. The default is PT5M (5 minutes). | PT10M |
| Max files to retrieve | Number | No | The maximum number of generated files to retrieve. The default is 10. | |
| Max total file size | Number | No | The maximum total size of the retrieved files in bytes. The default is 10485760 (10 MB). |
The session timeout controls how long the sandbox environment remains available, not how long the code takes to execute. Code execution typically completes in seconds.
The sandbox environment includes common Python libraries such as matplotlib, pandas, numpy, and csv. Network access is not available in the sandbox.
File handling
Any files created by the code during execution are automatically detected and returned as Camunda documents in the files field. This includes images (for example, charts saved with plt.savefig()), CSV files, text files, and other output files. Hidden files (names starting with a dot) are not returned.
Retrieval is limited by Max files to retrieve and Max total file size. Files beyond these limits are not returned, and a warning is logged.
Output
The connector returns the following fields:
| Field | Description |
|---|---|
stdout | The standard output printed by the code. |
stderr | Any error output produced during execution. |
exitCode | The process exit code. A value of 0 indicates successful execution. |
executionTimeMs | The execution duration in milliseconds. |
files | A list of Camunda documents for any files generated by the code. |
To map specific fields into process variables, use Result expression. For example, to extract the output and generated files:
= {
output: stdout,
files: files
}
Example: Run a calculation
Code:
total = sum([12000, 8500, 15000, 9200])
print(f"Total claims: ${total:,}")
Response:
{
"stdout": "Total claims: $44,700\n",
"stderr": "",
"exitCode": 0,
"executionTimeMs": 0.05,
"files": []
}
Example: Generate a chart
Code:
import matplotlib.pyplot as plt
plt.bar(["Q1", "Q2", "Q3", "Q4"], [12000, 8500, 15000, 9200])
plt.title("Claims by Quarter")
plt.ylabel("Amount ($)")
plt.savefig("chart.png")
print("Chart saved")
Response:
{
"stdout": "Chart saved\n",
"stderr": "",
"exitCode": 0,
"executionTimeMs": 1.67,
"files": [
{
"storeId": "in-memory",
"documentId": "851505b2-61bd-4717-9c86-07678b67f033",
"metadata": {
"contentType": "image/png",
"size": 14734,
"fileName": "chart.png"
},
"camunda.document.type": "camunda"
}
]
}
Example: Generate a CSV report
Code:
import csv
with open("claims.csv", "w", newline="") as f:
w = csv.writer(f)
w.writerow(["ClaimID", "Amount", "Status"])
w.writerows([["C001", 45000, "Rejected"], ["C002", 12000, "Approved"]])
print("Report created")
Response:
{
"stdout": "Report created\n",
"stderr": "",
"exitCode": 0,
"executionTimeMs": 0.05,
"files": [
{
"storeId": "in-memory",
"documentId": "c209e3a4-cefa-4622-adc1-88c92bf06bb2",
"metadata": {
"contentType": "text/csv",
"size": 80,
"fileName": "claims.csv"
},
"camunda.document.type": "camunda"
}
]
}
Troubleshooting
To learn about general error handling in Camunda, see BPMN errors and failing jobs.
Connector-specific errors
The connector fails the job with the error code CODE_INTERPRETER_FAILED when Code is empty, when the AWS service returns an error, or when the invocation times out or is interrupted. To handle it in your process, use Error expression.