---
title: "POST /code-interpreters/{codeInterpreterIdentifier}/tools/invoke"
method: POST
path: "/code-interpreters/{codeInterpreterIdentifier}/tools/invoke"
---

# POST /code-interpreters/{codeInterpreterIdentifier}/tools/invoke

`POST /code-interpreters/{codeInterpreterIdentifier}/tools/invoke`

Executes code within an active code interpreter session in Amazon Bedrock AgentCore. This operation processes the provided code, runs it in a secure environment, and returns the execution results including output, errors, and generated visualizations.

To execute code, you must specify the code interpreter identifier, session ID, and the code to run in the arguments parameter. The operation returns a stream containing the execution results, which can include text output, error messages, and data visualizations.

This operation is subject to request rate limiting based on your account's service quotas.

The following operations are related to `InvokeCodeInterpreter`:

*   [StartCodeInterpreterSession](https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_StartCodeInterpreterSession.html)
    
*   [GetCodeInterpreterSession](https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_GetCodeInterpreterSession.html)

## Path parameters

- `codeInterpreterIdentifier` string, required

## Headers

- `x-amzn-code-interpreter-session-id` string
- `X-Amzn-Trace-Id` string
- `traceparent` string

## Request body

- object
  - `name` 'executeCode' | 'executeCommand' | 'readFiles' | 'listFiles' | 'removeFiles' | 'writeFiles' | 'startCommandExecution' | 'getTask' | 'stopTask', required — The name of the code interpreter to invoke.
  - `arguments` object — The collection of arguments that specify the operation to perform and its parameters when invoking a tool in Amazon Bedrock AgentCore. Different tools require different arguments, and this structure provides a flexible way to pass the appropriate arguments to each tool type.
    - `code` string — The code to execute in a code interpreter session. This is the source code in the specified programming language that will be executed by the code interpreter.
    - `language` 'python' | 'javascript' | 'typescript' — The programming language of the code to execute. This tells the code interpreter which language runtime to use for execution.
    - `clearContext` boolean — Whether to clear the context for the tool.
    - `command` string — The command to execute with the tool.
    - `path` string — The path for the tool operation.
    - `paths` MaxLenString[] — The paths for the tool operation.
    - `content` InputContentBlock[] — The content for the tool operation.
      - `path` string, required — The path to the input content.
      - `text` string — The text input content.
      - `blob` string, password — The binary input content.
    - `directoryPath` string — The directory path for the tool operation.
    - `taskId` string — The identifier of the task for the tool operation.
    - `runtime` 'nodejs' | 'deno' | 'python' — The runtime environment to use for code execution. If not specified, defaults to <code>deno</code> for JavaScript and TypeScript.

## Response `200`

Success

- InvokeCodeInterpreterResponse
  - `stream` object, required — The stream containing the results of the code execution. This includes output, errors, and execution status.
    - `result` CodeInterpreterResult — The output produced by executing code in a code interpreter session in Amazon Bedrock AgentCore. This structure contains the results of code execution, including textual output, structured data, and error information. Agents use these results to generate responses that incorporate computation, data analysis, and visualization.
      - `content` ContentBlock[], required — The textual content of the execution result. This includes standard output from the code execution, such as print statements, console output, and text representations of results.
        - `type` 'text' | 'image' | 'resource' | 'resource_link', required — The type of content in the block.
        - `text` string — The text content of the block.
        - `data` string — The binary data content of the block.
        - `mimeType` string — The MIME type of the content.
        - `uri` string — The URI of the content.
        - `name` string — The name of the content block.
        - `description` string — The description of the content block.
        - `size` integer — The size of the content in bytes.
        - `resource` object — The resource associated with the content block.
          - `type` 'text' | 'blob', required — The type of resource content.
          - `uri` string — The URI of the resource content.
          - `mimeType` string — The MIME type of the resource content.
          - `text` string — The text resource content.
          - `blob` string — The binary resource content.
      - `structuredContent` object — The structured content of the execution result. This includes additional metadata about the execution, such as execution time, memory usage, and structured representations of output data. The format depends on the specific code interpreter and execution context.
        - `taskId` string — The identifier of the task that produced the result.
        - `taskStatus` 'submitted' | 'working' | 'completed' | 'canceled' | 'failed' — The status of the task that produced the result.
        - `stdout` string — The standard output from the tool execution.
        - `stderr` string — The standard error output from the tool execution.
        - `exitCode` integer — The exit code from the tool execution.
        - `executionTime` number, double — The execution time of the tool operation in milliseconds.
      - `isError` boolean — Indicates whether the result represents an error. If true, the content contains error messages or exception information. If false, the content contains successful execution results.
    - `accessDeniedException` AccessDeniedException — The exception that occurs when you do not have sufficient permissions to perform an action. Verify that your IAM policy includes the necessary permissions for the operation you are trying to perform.
      - `message` string
    - `conflictException` ConflictException — The exception that occurs when the request conflicts with the current state of the resource. This can happen when trying to modify a resource that is currently being modified by another request, or when trying to create a resource that already exists.
      - `message` string
    - `internalServerException` InternalServerException — The exception that occurs when the service encounters an unexpected internal error. This is a temporary condition that will resolve itself with retries. We recommend implementing exponential backoff retry logic in your application.
      - `message` string
    - `resourceNotFoundException` ResourceNotFoundException — The exception that occurs when the specified resource does not exist. This can happen when using an invalid identifier or when trying to access a resource that has been deleted.
      - `message` string
    - `serviceQuotaExceededException` ServiceQuotaExceededException — The exception that occurs when the request would cause a service quota to be exceeded. Review your service quotas and either reduce your request rate or request a quota increase.
      - `message` string
    - `throttlingException` ThrottlingException — The exception that occurs when the request was denied due to request throttling. This happens when you exceed the allowed request rate for an operation. Reduce the frequency of requests or implement exponential backoff retry logic in your application.
      - `message` string
    - `validationException` ValidationException — The exception that occurs when the input fails to satisfy the constraints specified by the service. Check the error message for details about which input parameter is invalid and correct your request.
      - `message` string, required
      - `reason` 'CannotParse' | 'FieldValidationFailed' | 'IdempotentParameterMismatchException' | 'EventInOtherSession' | 'ResourceConflict', required
      - `fieldList` ValidationExceptionField[]
        - `name` string, required — The name of the field.
        - `message` string, required — A message describing why this field failed validation.

## Other responses

- `480` — ServiceQuotaExceededException
- `481` — AccessDeniedException
- `482` — ConflictException
- `483` — ValidationException
- `484` — ResourceNotFoundException
- `485` — ThrottlingException
- `486` — InternalServerException

---

[API](https://skmtc.net/aws/apis/bedrock-agentcore.md) · [All operations](https://skmtc.net/aws/apis/bedrock-agentcore/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/aws/bedrock-agentcore/versions/79623b33d495/schema)
