Skip to content
View as Markdown

Stateful code interpretation interface for a Sandbox.

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

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
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
public InterpreterContext createContext()

Creates a new interpreter context using sandbox defaults.

Returns:

  • InterpreterContext - created interpreter context metadata

Throws:

  • DaytonaException - if context creation fails
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
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
public void deleteContext(String contextId)

Deletes an interpreter context.

Parameters:

  • contextId String - context identifier to delete

Throws:

  • DaytonaException - if deletion fails

Options for CodeInterpreter#runCode(String, RunCodeOptions).

public RunCodeOptions()
public Integer getTimeout()

Returns:

  • Integer -
public RunCodeOptions setTimeout(Integer timeout)

Parameters:

  • timeout Integer -

Returns:

  • RunCodeOptions -
public Consumer<String> getOnStdout()

Returns:

  • Consumer\<String\> -
public RunCodeOptions setOnStdout(Consumer<String> onStdout)

Parameters:

  • onStdout Consumer<String> -

Returns:

  • RunCodeOptions -
public Consumer<String> getOnStderr()

Returns:

  • Consumer\<String\> -
public RunCodeOptions setOnStderr(Consumer<String> onStderr)

Parameters:

  • onStderr Consumer<String> -

Returns:

  • RunCodeOptions -
public Consumer<CodeInterpreter.ExecutionError> getOnError()

Returns:

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

Parameters:

  • onError Consumer<CodeInterpreter.ExecutionError> -

Returns:

  • RunCodeOptions -