DaytonaDocs

Process

Command execution, code runs, and sessions.

Process runs commands and code inside a sandbox, and manages long-running background sessions. Obtain it as sandbox.process — see the running commands guide for a task-oriented walkthrough.

exec()

Executes a shell command inside the sandbox and waits for it to finish. execute_command is an exact alias, kept for Daytona parity — the two names call the same implementation.

Python
def exec(
    command: str,
    cwd: str | None = None,
    env: Dict[str, str] | None = None,
    timeout: int | None = None,
) -> ExecuteResponse
ParameterTypeDefaultDescription
commandstrShell command to run.
cwdstrNoneWorking directory.
envDict[str, str]NoneExtra environment variables for this command.
timeoutintNoneSeconds before the command is killed.

Returns: ExecuteResponse with exit_code: int, result: str (combined output), and artifacts (a dict containing stdout).

Python
result = sandbox.process.exec("ls -la", cwd="/tmp", timeout=30)
print(result.exit_code, result.result)

code_run()

Executes a code string using the sandbox's configured language runtime. The language comes from the code-toolbox-language label set at sandbox creation; without it this raises ValueError.

Python
def code_run(
    code: str,
    params: CodeRunParams | None = None,
    timeout: int | None = None,
) -> ExecuteResponse
ParameterTypeDefaultDescription
codestrSource code to run.
paramsCodeRunParamsNoneargv: List[str] and/or env: Dict[str, str].
timeoutintNoneSeconds before the run is killed.

Returns: ExecuteResponse (same shape as exec). Raises: ValueError when the sandbox has no configured code language.

Python
result = sandbox.process.code_run("print(sum(range(10)))")
print(result.result)  # 45

Sessions

Sessions are long-running background shells: create one, execute commands in it (synchronously or async), stream logs, send input, and delete it when done. State (working directory, environment) persists between commands in the same session.

create_session()

Creates a new background session with the id you choose.

Python
def create_session(session_id: str) -> None

get_session()

Fetches a session and its command history.

Python
def get_session(session_id: str) -> Dict[str, Any]

list_sessions()

Lists all active sessions in the sandbox.

Python
def list_sessions() -> List[Dict[str, Any]]

execute_session_command()

Executes a command inside an existing session. With run_async=True in the request, the call returns immediately with a command id you can poll via get_session_command() / get_session_command_logs().

Python
def execute_session_command(
    session_id: str,
    req: SessionExecuteRequest,
    timeout: int | None = None,
) -> Dict[str, Any]
ParameterTypeDefaultDescription
session_idstrTarget session.
reqSessionExecuteRequestcommand: str, run_async: bool = False, suppress_input_echo: bool = False.
timeoutintNoneRequest timeout in seconds.

Returns: a dict including cmdId, plus stdout/stderr (defaulted to "") and exitCode/output when the command ran synchronously.

Python
from rlp import SessionExecuteRequest
 
sandbox.process.create_session("build")
res = sandbox.process.execute_session_command(
    "build", SessionExecuteRequest(command="make -j4", run_async=True)
)
logs = sandbox.process.get_session_command_logs("build", res["cmdId"])

get_session_command()

Fetches metadata (command line, exit code) for one command previously executed in a session.

Python
def get_session_command(session_id: str, command_id: str) -> Dict[str, Any]

get_session_command_logs()

Fetches the accumulated logs of a session command.

Python
def get_session_command_logs(session_id: str, command_id: str) -> Dict[str, Any]

Returns: a dict with output, stdout, and stderr (each defaulted to "").

send_session_command_input()

Sends input to a running session command's stdin — for interactive programs awaiting input.

Python
def send_session_command_input(session_id: str, command_id: str, data: str) -> None

delete_session()

Deletes a session and terminates anything still running in it.

Python
def delete_session(session_id: str) -> None

On this page