# Class ContainerCodeExecutor

java.lang.Object
com.google.adk.JsonBaseModel
com.google.adk.codeexecutors.BaseCodeExecutor
com.google.adk.codeexecutors.ContainerCodeExecutor

public class ContainerCodeExecutor extends BaseCodeExecutor
A code executor that uses a custom container to execute code.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ContainerCodeExecutor(String baseUrl, String image, String dockerPath)`
  Deprecated.
  Use one of the static factory methods instead.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `CodeExecutionUtils.CodeExecutionResult`
  `executeCode(InvocationContext invocationContext, CodeExecutionUtils.CodeExecutionInput codeExecutionInput)`
  Executes code and return the code execution result.
  `static ContainerCodeExecutor`
  `fromDockerPath(String dockerPath)`
  Creates a ContainerCodeExecutor from a Dockerfile path.
  `static ContainerCodeExecutor`
  `fromDockerPath(String baseUrl, String dockerPath)`
  Creates a ContainerCodeExecutor from a Dockerfile path.
  `static ContainerCodeExecutor`
  `fromImage(String image)`
  Creates a ContainerCodeExecutor from an image.
  `static ContainerCodeExecutor`
  `fromImage(String baseUrl, String image)`
  Creates a ContainerCodeExecutor from an image.
  `boolean`
  `optimizeDataFile()`
  If true, extract and process data files from the model request and attach them to the code executor.
  `boolean`
  `stateful()`
  Whether the code executor is stateful.

  ### Methods inherited from class BaseCodeExecutor

  `codeBlockDelimiters, errorRetryAttempts, executionResultDelimiters`
  Modifier and Type
  Method
  Description
  `com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<String>>`
  `codeBlockDelimiters()`
  The list of the enclosing delimiters to identify the code blocks.
  `int`
  `errorRetryAttempts()`
  The number of attempts to retry on consecutive code execution errors.
  `com.google.common.collect.ImmutableList<String>`
  `executionResultDelimiters()`
  The delimiters to format the code execution result.

  ### Methods inherited from class JsonBaseModel

  `fromJsonNode, fromJsonString, getMapper, toJson, toJsonNode, toJsonString`
  Modifier and Type
  Method
  Description
  `static <T extends JsonBaseModel>
  T`
  `fromJsonNode(com.fasterxml.jackson.databind.JsonNode jsonNode, Class<T> clazz)`
  Deserializes a JsonNode to an object of the given type.
  `static <T extends JsonBaseModel>
  T`
  `fromJsonString(String jsonString, Class<T> clazz)`
  Deserializes a Json string to an object of the given type.
  `static com.fasterxml.jackson.databind.ObjectMapper`
  `getMapper()`
  Returns the mutable ObjectMapper instance used by ADK.
  `String`
  `toJson()`
  Serializes this object (i.e., the ObjectMappper instance used by ADK) to a Json string.
  `protected static com.fasterxml.jackson.databind.JsonNode`
  `toJsonNode(Object object)`
  Serializes an object to a JsonNode.
  `static String`
  `toJsonString(Object object)`
  Serializes an object to a Json string.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ContainerCodeExecutor

    @Deprecated public ContainerCodeExecutor(String baseUrl, String image, String dockerPath)
    Deprecated.
    Use one of the static factory methods instead.
    Initializes the ContainerCodeExecutor. Either dockerPath or image must be set.

- ## Method Details

  - ### fromImage

    public static ContainerCodeExecutor fromImage(String baseUrl, String image)
    Creates a ContainerCodeExecutor from an image.
    Parameters:
      `baseUrl` - The base url of the user hosted Docker client.
      `image` - The tag of the predefined image or custom image to run on the container.

  - ### fromImage

    public static ContainerCodeExecutor fromImage(String image)
    Creates a ContainerCodeExecutor from an image.
    Parameters:
      `image` - The tag of the predefined image or custom image to run on the container.

  - ### fromDockerPath

    public static ContainerCodeExecutor fromDockerPath(String baseUrl, String dockerPath)
    Creates a ContainerCodeExecutor from a Dockerfile path.
    Parameters:
      `baseUrl` - The base url of the user hosted Docker client.
      `dockerPath` - The path to the directory containing the Dockerfile.

  - ### fromDockerPath

    public static ContainerCodeExecutor fromDockerPath(String dockerPath)
    Creates a ContainerCodeExecutor from a Dockerfile path.
    Parameters:
      `dockerPath` - The path to the directory containing the Dockerfile.

  - ### stateful

    public boolean stateful()
    Description copied from class: `BaseCodeExecutor`
    Whether the code executor is stateful. Default to False.
    Overrides:
      `stateful` in class `BaseCodeExecutor`

  - ### optimizeDataFile

    public boolean optimizeDataFile()
    Description copied from class: `BaseCodeExecutor`
    If true, extract and process data files from the model request and attach them to the code executor.

    Supported data file MimeTypes are [text/csv]. Default to False.

    Overrides:
      `optimizeDataFile` in class `BaseCodeExecutor`

  - ### executeCode

    public CodeExecutionUtils.CodeExecutionResult executeCode(InvocationContext invocationContext, CodeExecutionUtils.CodeExecutionInput codeExecutionInput)
    Description copied from class: `BaseCodeExecutor`
    Executes code and return the code execution result.

    This method may perform blocking operations.

    Specified by:
      `executeCode` in class `BaseCodeExecutor`
    Parameters:
      `invocationContext` - The invocation context of the code execution.
      `codeExecutionInput` - The code execution input.
    Returns:
      The code execution result.