Skip to content

invoke_code_interpreter

Operation

Async only

This operation uses an event stream, so only the asynchronous client supports it.

invoke_code_interpreter async

invoke_code_interpreter(request: InvokeCodeInterpreterInput | InvokeCodeInterpreterInputDict | None = None, /, *, plugins: list[Plugin] | None = None, **kwargs: Unpack[InvokeCodeInterpreterInputDict]) -> AsyncOutputEventStream[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
request InvokeCodeInterpreterInput | InvokeCodeInterpreterInputDict | None

The input as a model or dictionary. Pass this or keyword arguments, not both.

None
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
**kwargs Unpack[InvokeCodeInterpreterInputDict]

The input fields as keyword arguments.

{}

Returns:

Type Description
AsyncOutputEventStream[CodeInterpreterStreamOutput, InvokeCodeInterpreterOutput]

An AsyncOutputEventStream for server-to-client streaming.

Input

Pass the input as keyword arguments, a positional dictionary, or a positional model object. Pass plugins separately as a keyword argument.

InvokeCodeInterpreterInputDict

Bases: TypedDict

Dictionary form of InvokeCodeInterpreterInput.

Attributes

arguments instance-attribute
arguments: ToolArguments | ToolArgumentsDict | 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 instance-attribute
code_interpreter_identifier: Required[str]

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

name instance-attribute
name: Required[str]

The name of the code interpreter to invoke.

session_id instance-attribute
session_id: str | 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 instance-attribute
trace_id: str | None

The trace identifier for request tracking.

trace_parent instance-attribute
trace_parent: str | None

The parent trace information for distributed tracing.

InvokeCodeInterpreterInput dataclass

Bases: _SerdeShape

Dataclass for InvokeCodeInterpreterInput structure.

Attributes

arguments class-attribute instance-attribute
arguments: ToolArguments | 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 = ...

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: str | None = ...

The name of the code interpreter to invoke.

session_id class-attribute instance-attribute
session_id: str | 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 = ...

The trace identifier for request tracking.

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

The parent trace information for distributed tracing.

Output

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

Event Stream Structure

Output Event Type

CodeInterpreterStreamOutput

Initial Response Structure

InvokeCodeInterpreterOutput dataclass

Bases: _SerdeShape

Dataclass for InvokeCodeInterpreterOutput structure.

Attributes
response_metadata class-attribute instance-attribute
response_metadata: ResponseMetadata = ...

Metadata about the response that produced this output. Use this to recover the request identifiers a service's support team needs in order to investigate a call. Members of the metadata are individually optional.

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

The identifier of the code interpreter session.