Skip to content

Bedrock Agentcore  >  Operations  >  invoke_code_interpreter

invoke_code_interpreter

Operation

invoke_code_interpreter async

invoke_code_interpreter(input: InvokeCodeInterpreterInput, plugins: list[Plugin] | None = None) -> OutputEventStream[CodeInterpreterStreamOutput, InvokeCodeInterpreterOutput]

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:

Parameters:

Name Type Description Default
input InvokeCodeInterpreterInput

An instance of InvokeCodeInterpreterInput.

required
plugins list[Plugin] | None

A list of callables that modify the configuration dynamically. Changes made by these plugins only apply for the duration of the operation execution and will not affect any other operation invocations.

None

Returns:

Type Description
OutputEventStream[CodeInterpreterStreamOutput, InvokeCodeInterpreterOutput]

An OutputEventStream for server-to-client streaming.

Input

InvokeCodeInterpreterInput dataclass

Dataclass for InvokeCodeInterpreterInput structure.

Attributes

arguments class-attribute instance-attribute
arguments: ToolArguments | None = None

The arguments for the code interpreter. This includes the code to execute and any additional parameters such as the programming language, whether to clear the execution context, and other execution options. The structure of this parameter depends on the specific code interpreter being used.

code_interpreter_identifier class-attribute instance-attribute
code_interpreter_identifier: str | None = None

The unique identifier of the code interpreter associated with the session. This must match the identifier used when creating the session with StartCodeInterpreterSession.

name class-attribute instance-attribute
name: ToolName | None = None

The name of the code interpreter to invoke.

session_id class-attribute instance-attribute
session_id: str | None = None

The unique identifier of the code interpreter session to use. This must be an active session created with StartCodeInterpreterSession. If the session has expired or been stopped, the request will fail.

trace_id class-attribute instance-attribute
trace_id: str | None = None

The trace identifier for request tracking.

trace_parent class-attribute instance-attribute
trace_parent: str | None = None

The parent trace information for distributed tracing.

Output

This operation returns an OutputEventStream for server-to-client streaming.

Event Stream Structure

Output Event Type

CodeInterpreterStreamOutput

Initial Response Structure

InvokeCodeInterpreterOutput dataclass

Dataclass for InvokeCodeInterpreterOutput structure.

Attributes
session_id class-attribute instance-attribute
session_id: str | None = None

The identifier of the code interpreter session.