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:
codeString - 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:
codeString - Python code to executeoptionsRunCodeOptions - execution options including callbacks and timeout; may benull
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:
cwdString - working directory for the new context;nulluses 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:
contextIdString - 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:
timeoutInteger -
Returns:
RunCodeOptions-
getOnStdout()
public Consumer<String> getOnStdout()Returns:
Consumer\<String\>-
setOnStdout()
public RunCodeOptions setOnStdout(Consumer<String> onStdout)Parameters:
onStdoutConsumer<String> -
Returns:
RunCodeOptions-
getOnStderr()
public Consumer<String> getOnStderr()Returns:
Consumer\<String\>-
setOnStderr()
public RunCodeOptions setOnStderr(Consumer<String> onStderr)Parameters:
onStderrConsumer<String> -
Returns:
RunCodeOptions-
getOnError()
public Consumer<CodeInterpreter.ExecutionError> getOnError()Returns:
Consumer\<CodeInterpreter.ExecutionError\>-
setOnError()
public RunCodeOptions setOnError(Consumer<CodeInterpreter.ExecutionError> onError)Parameters:
onErrorConsumer<CodeInterpreter.ExecutionError> -
Returns:
RunCodeOptions-