Skip to content
View as Markdown

CodeInterpreter

Stateful code interpretation interface for a Sandbox.

Provides Python code execution in interpreter contexts that preserve state between runs.

Methods

runCode()

public ExecutionResult runCode(String code)

Executes Python code in the default interpreter context.

Parameters:

  • code String - Python code to execute

Returns:

  • ExecutionResult - aggregated execution result

Throws:

  • DaytonaException - if code is empty, connection fails, or execution fails

runCode()

public ExecutionResult runCode(String code, RunCodeOptions options)

Executes Python code with streaming callbacks and options.

Parameters:

  • code String - Python code to execute
  • options RunCodeOptions - execution options including callbacks and timeout; may be null

Returns:

  • ExecutionResult - aggregated execution result

Throws:

  • DaytonaException - if code is empty, connection fails, or execution fails

createContext()

public InterpreterContext createContext()

Creates a new interpreter context using sandbox defaults.

Returns:

  • InterpreterContext - created interpreter context metadata

Throws:

  • DaytonaException - if context creation fails

createContext()

public InterpreterContext createContext(String cwd)

Creates a new interpreter context.

Parameters:

  • cwd String - working directory for the new context; null uses sandbox default

Returns:

  • InterpreterContext - created interpreter context metadata

Throws:

  • DaytonaException - if context creation fails

listContexts()

public List<InterpreterContext> listContexts()

Lists all user-created interpreter contexts.

Returns:

  • List\<InterpreterContext\> - list of interpreter contexts; empty list when no contexts exist

Throws:

  • DaytonaException - if listing contexts fails

deleteContext()

public void deleteContext(String contextId)

Deletes an interpreter context.

Parameters:

  • contextId String - context identifier to delete

Throws:

  • DaytonaException - if deletion fails

RunCodeOptions

Options for CodeInterpreter#runCode(String, RunCodeOptions).

Constructors

new RunCodeOptions()

public RunCodeOptions()

Methods

getTimeout()

public Integer getTimeout()

Returns:

  • Integer -

setTimeout()

public RunCodeOptions setTimeout(Integer timeout)

Parameters:

  • timeout Integer -

Returns:

  • RunCodeOptions -

getOnStdout()

public Consumer<String> getOnStdout()

Returns:

  • Consumer\<String\> -

setOnStdout()

public RunCodeOptions setOnStdout(Consumer<String> onStdout)

Parameters:

  • onStdout Consumer<String> -

Returns:

  • RunCodeOptions -

getOnStderr()

public Consumer<String> getOnStderr()

Returns:

  • Consumer\<String\> -

setOnStderr()

public RunCodeOptions setOnStderr(Consumer<String> onStderr)

Parameters:

  • onStderr Consumer<String> -

Returns:

  • RunCodeOptions -

getOnError()

public Consumer<CodeInterpreter.ExecutionError> getOnError()

Returns:

  • Consumer\<CodeInterpreter.ExecutionError\> -

setOnError()

public RunCodeOptions setOnError(Consumer<CodeInterpreter.ExecutionError> onError)

Parameters:

  • onError Consumer<CodeInterpreter.ExecutionError> -

Returns:

  • RunCodeOptions -