ProcessHandle
Section titled “ProcessHandle”class ProcessHandle()Serializable handle for one daemon process.
ProcessHandle.__init__
Section titled “ProcessHandle.__init__”def __init__(impl: AsyncProcessHandle, bridge: SyncBridge) -> NoneProcessHandle.sandbox_id
Section titled “ProcessHandle.sandbox_id”@propertydef sandbox_id() -> strProcessHandle.process_id
Section titled “ProcessHandle.process_id”@propertydef process_id() -> strProcessHandle.id
Section titled “ProcessHandle.id”@propertydef id() -> strProcessHandle.kind
Section titled “ProcessHandle.kind”@propertydef kind() -> Literal['exec', 'pty', 'code', 'session'] | NoneProcessHandle.attach
Section titled “ProcessHandle.attach”def attach() -> NoneAttach is optional in Python because no runtime WebSocket dependency is bundled.
ProcessHandle.delete
Section titled “ProcessHandle.delete”def delete() -> NoneDelete the process record and retained logs, stopping it first.
ProcessHandle.from_json
Section titled “ProcessHandle.from_json”@classmethoddef from_json(value: Mapping[str, str]) -> ProcessHandleRehydrate a handle identity without making a network request.
ProcessHandle.get
Section titled “ProcessHandle.get”def get() -> ProcessInfoFetch current process metadata.
ProcessHandle.kill
Section titled “ProcessHandle.kill”def kill(*, signal: SignalName = 'TERM', escalate_after: Optional[float] = None, escalate_to: SignalName = 'KILL') -> NoneSend a signal and optional escalation signal.
ProcessHandle.logs
Section titled “ProcessHandle.logs”def logs(*, cursor: Optional[str] = None, limit: Optional[int] = None, encoding: LogEncoding = 'text') -> LogPageRead a cursor-replayable process log page.
ProcessHandle.ref
Section titled “ProcessHandle.ref”def ref() -> ProcessHandleRefReturn a typed handle identity.
ProcessHandle.resize
Section titled “ProcessHandle.resize”def resize(cols: int, rows: int) -> NoneResize a PTY process.
ProcessHandle.stdin
Section titled “ProcessHandle.stdin”def stdin(data: Union[str, bytes], *, eof: bool = False) -> NoneWrite stdin to an exec or PTY process created with stdin=‘open’.
ProcessHandle.stdin_eof
Section titled “ProcessHandle.stdin_eof”def stdin_eof() -> NoneClose stdin for an exec or PTY process.
ProcessHandle.stream_logs
Section titled “ProcessHandle.stream_logs”def stream_logs(*, cursor: Optional[str] = None, encoding: LogEncoding = 'text') -> Iterator[LogFrame]Follow process logs with SSE while retaining cursor replay semantics.
ProcessHandle.to_json
Section titled “ProcessHandle.to_json”def to_json() -> Dict[str, str]Return a JSON-safe handle identity.
ProcessHandle.wait
Section titled “ProcessHandle.wait”def wait(*, timeout: Optional[float] = None) -> WaitResultWait for terminal state using the daemon long-poll contract.
AsyncProcessHandle
Section titled “AsyncProcessHandle”class AsyncProcessHandle()Serializable handle for one daemon process.
AsyncProcessHandle.__init__
Section titled “AsyncProcessHandle.__init__”def __init__(sandbox_id: str, process_id: str, transport: Optional[AsyncTransport] = None, kind: Optional[ProcessKind] = None) -> NoneAsyncProcessHandle.to_json
Section titled “AsyncProcessHandle.to_json”def to_json() -> Dict[str, str]Return a JSON-safe handle identity.
AsyncProcessHandle.from_json
Section titled “AsyncProcessHandle.from_json”@classmethoddef from_json(value: Mapping[str, str]) -> AsyncProcessHandleRehydrate a handle identity without making a network request.
AsyncProcessHandle.ref
Section titled “AsyncProcessHandle.ref”def ref() -> ProcessHandleRefReturn a typed handle identity.
AsyncProcessHandle.bind
Section titled “AsyncProcessHandle.bind”def bind(transport: AsyncTransport) -> AsyncProcessHandleReturn this handle bound to a transport.
AsyncProcessHandle.get
Section titled “AsyncProcessHandle.get”async def get() -> ProcessInfoFetch current process metadata.
AsyncProcessHandle.wait
Section titled “AsyncProcessHandle.wait”async def wait(*, timeout: Optional[float] = None) -> WaitResultWait for terminal state using the daemon long-poll contract.
timeout is the caller wait budget in seconds; 0 waits
unbounded.
AsyncProcessHandle.logs
Section titled “AsyncProcessHandle.logs”async def logs(*, cursor: Optional[str] = None, limit: Optional[int] = None, encoding: LogEncoding = 'text') -> LogPageRead a cursor-replayable process log page.
AsyncProcessHandle.stream_logs
Section titled “AsyncProcessHandle.stream_logs”async def stream_logs(*, cursor: Optional[str] = None, encoding: LogEncoding = 'text') -> AsyncIterator[LogFrame]Follow process logs with SSE while retaining cursor replay semantics.
AsyncProcessHandle.stdin
Section titled “AsyncProcessHandle.stdin”async def stdin(data: Union[str, bytes], *, eof: bool = False) -> NoneWrite stdin to an exec or PTY process created with stdin=‘open’.
AsyncProcessHandle.stdin_eof
Section titled “AsyncProcessHandle.stdin_eof”async def stdin_eof() -> NoneClose stdin for an exec or PTY process.
AsyncProcessHandle.kill
Section titled “AsyncProcessHandle.kill”async def kill(*, signal: SignalName = 'TERM', escalate_after: Optional[float] = None, escalate_to: SignalName = 'KILL') -> NoneSend a signal and optional escalation signal.
AsyncProcessHandle.resize
Section titled “AsyncProcessHandle.resize”async def resize(cols: int, rows: int) -> NoneResize a PTY process.
AsyncProcessHandle.attach
Section titled “AsyncProcessHandle.attach”def attach() -> NoneAttach is optional in Python because no runtime WebSocket dependency is bundled.
AsyncProcessHandle.delete
Section titled “AsyncProcessHandle.delete”async def delete() -> NoneDelete the process record and retained logs, stopping it first.
Raises UnsupportedOperationError for a running code cell and for a
session command that has not stopped within 5 s: delete its session.
ProcessService
Section titled “ProcessService”class ProcessService()Sandbox process namespace.
ProcessService.__init__
Section titled “ProcessService.__init__”def __init__(impl: AsyncProcessService, bridge: SyncBridge) -> NoneProcessService.connect
Section titled “ProcessService.connect”def connect(process_id: Union[str, Mapping[str, str]]) -> ProcessHandleCreate a bound process handle without fetching metadata.
ProcessService.connect_session
Section titled “ProcessService.connect_session”def connect_session(session_id: str | Mapping[str, object]) -> SessionBind a session id or serialized identity without making a request.
ProcessService.create_session
Section titled “ProcessService.create_session”def create_session(*, cwd: Optional[str] = None, env: Optional[Mapping[str, str]] = None, shell: Optional[str] = None, login: Optional[bool] = None, name: Optional[str] = None) -> SessionCreate one persistent shell; cwd and env apply to all its commands.
ProcessService.get
Section titled “ProcessService.get”def get(process_id: str) -> ProcessInfoFetch current process metadata by id or live name alias.
ProcessService.list
Section titled “ProcessService.list”def list(*, state: Optional[ProcessStateFilter] = None, kind: Optional[ProcessKind] = None, session_id: Optional[str] = None, name: Optional[str] = None, pid: Optional[int] = None) -> ListResult[ProcessInfo]ProcessService.run
Section titled “ProcessService.run”def run(command: Optional[str] = None, *, argv: Optional[Sequence[str]] = None, cwd: Optional[str] = None, env: Optional[Mapping[str, str]] = None, user: Optional[str] = None, shell: Optional[str] = None, login: Optional[bool] = None, stdin: StdinMode = 'closed', timeout: Optional[float] = None, execution_timeout: Optional[float] = None, name: Optional[str] = None, terminal: Optional[TerminalSize] = None, keep_logs: Optional[KeepLogs] = None) -> ProcessResultStart a process, wait for its shell to exit, and collect its output.
ProcessService.start
Section titled “ProcessService.start”def start(command: Optional[str] = None, *, argv: Optional[Sequence[str]] = None, name: Optional[str] = None, cwd: Optional[str] = None, env: Optional[Mapping[str, str]] = None, user: Optional[str] = None, shell: Optional[str] = None, login: Optional[bool] = None, stdin: StdinMode = 'closed', execution_timeout: Optional[float] = None, terminal: Optional[TerminalSize] = None, keep_logs: Optional[KeepLogs] = None) -> ProcessHandleStart a detached process and return a handle immediately.
AsyncProcessService
Section titled “AsyncProcessService”class AsyncProcessService()Sandbox process namespace.
AsyncProcessService.__init__
Section titled “AsyncProcessService.__init__”def __init__(sandbox_id: str, transport: AsyncTransport, language: Optional[str] = None) -> NoneAsyncProcessService.create_session
Section titled “AsyncProcessService.create_session”async def create_session(*, cwd: Optional[str] = None, env: Optional[Mapping[str, str]] = None, shell: Optional[str] = None, login: Optional[bool] = None, name: Optional[str] = None) -> AsyncSessionCreate one persistent shell; cwd and env apply to all its commands.
shell must be a POSIX shell (bash, sh, dash, zsh, ksh) on Linux
and macOS; another shell is refused when the session is created. On
Windows, pwsh or powershell.
AsyncProcessService.connect_session
Section titled “AsyncProcessService.connect_session”def connect_session(session_id: str | Mapping[str, object]) -> AsyncSessionBind a session id or serialized identity without making a request.
AsyncProcessService.start
Section titled “AsyncProcessService.start”async def start(command: Optional[str] = None, *, argv: Optional[Sequence[str]] = None, name: Optional[str] = None, cwd: Optional[str] = None, env: Optional[Mapping[str, str]] = None, user: Optional[str] = None, shell: Optional[str] = None, login: Optional[bool] = None, stdin: StdinMode = 'closed', execution_timeout: Optional[float] = None, terminal: Optional[TerminalSize] = None, keep_logs: Optional[KeepLogs] = None) -> AsyncProcessHandleStart a detached process and return a handle immediately.
Unlike run, this returns as soon as the daemon has started the
process. Use the returned ProcessHandle to stream logs
(handle.stream_logs()), wait for exit (handle.wait()), or kill
(handle.kill()). This is the right choice for long-running servers —
call start() once, then poll the port or stream logs to confirm the
server is ready.
Shell selection. A string command runs through the sandbox shell
(bash, else sh; pin another with shell=). Quote globs and brackets
(pip install -e '.[test]'). Use argv= to bypass the shell for
untrusted input. For persistent shell state, use create_session.
:param command: Shell command string; mutually exclusive with argv.
:param argv: Argument vector for shell-free execution.
:param cwd: Working directory inside the sandbox.
:param env: Extra environment variables merged into the process environment.
:param shell: Shell binary to use (e.g. "bash"); overrides auto-detection.
:param execution_timeout: Server-side deadline in seconds. The daemon kills
the process tree when this expires.
:returns: Bound ProcessHandle — logs, wait, and kill are available
immediately.
Example — start an HTTP server and wait for it to be ready::
handle = await sandbox.process.start(“python3 -m http.server 8000”)
poll or stream logs; the process keeps running in the background
Section titled “poll or stream logs; the process keeps running in the background”AsyncProcessService.run
Section titled “AsyncProcessService.run”async def run(command: Optional[str] = None, *, argv: Optional[Sequence[str]] = None, cwd: Optional[str] = None, env: Optional[Mapping[str, str]] = None, user: Optional[str] = None, shell: Optional[str] = None, login: Optional[bool] = None, stdin: StdinMode = 'closed', timeout: Optional[float] = None, execution_timeout: Optional[float] = None, name: Optional[str] = None, terminal: Optional[TerminalSize] = None, keep_logs: Optional[KeepLogs] = None) -> ProcessResultStart a process, wait for its shell to exit, and collect its output.
The common case is one round trip: the daemon starts the process, parks
the request until it exits (or timeout expires), and returns the
output inline. A process that outlives the wait window or produces more
output than fits in one page falls back to split calls automatically.
The result holds the output the daemon still has when the call returns: its per-process log is bounded, so very large output loses its oldest frames, and a result that timed out collects only the first few log pages.
Shell selection. A string command runs through the sandbox shell
(bash, else sh; pin another with shell=). Quote globs and brackets
(pip install -e '.[test]') so the command means the same under any
shell. Use argv= to bypass the shell entirely, which is the safe
form for untrusted arguments. For persistent shell state, use create_session.
Background processes. The call returns when the shell exits. If the
command forks a background child that holds its output descriptors open
(e.g. python3 -m http.server 8000 &), the daemon waits at most ~2
seconds for output to drain and then returns; output the child writes
later is not part of the result. For a long-running server prefer
start, which returns a ProcessHandle immediately, or
redirect: nohup cmd > server.log 2>&1 &.
:param command: Shell command string; mutually exclusive with argv.
:param argv: Argument vector for shell-free execution.
:param cwd: Working directory inside the sandbox.
:param env: Extra environment variables merged into the process environment.
:param shell: Shell binary to use (e.g. "bash"); overrides auto-detection.
:param timeout: Caller wait budget in seconds. Omit to wait until the process
ends. Does not kill the process on expiry.
:param execution_timeout: Server-side deadline in seconds. The daemon kills
the process tree when this expires.
:returns: daytona.v2.types.ProcessResult with stdout, stderr,
output, exit_code, and reason.
Example::
result = await sandbox.process.run(“pip install httpx”) if result.exit_code != 0: raise RuntimeError(result.stderr)
AsyncProcessService.connect
Section titled “AsyncProcessService.connect”def connect(process_id: Union[str, Mapping[str, str]]) -> AsyncProcessHandleCreate a bound process handle without fetching metadata.
AsyncProcessService.get
Section titled “AsyncProcessService.get”async def get(process_id: str) -> ProcessInfoFetch current process metadata by id or live name alias.
AsyncProcessService.list
Section titled “AsyncProcessService.list”async def list(*, state: Optional[ProcessStateFilter] = None, kind: Optional[ProcessKind] = None, session_id: Optional[str] = None, name: Optional[str] = None, pid: Optional[int] = None) -> ListResult[ProcessInfo]PtyService
Section titled “PtyService”class PtyService()PTY convenience namespace.
PtyService.__init__
Section titled “PtyService.__init__”def __init__(impl: AsyncPtyService, bridge: SyncBridge) -> NonePtyService.connect
Section titled “PtyService.connect”def connect(process_id: str) -> ProcessHandleCreate a bound PTY handle.
PtyService.delete
Section titled “PtyService.delete”def delete(process_id: str) -> NonePtyService.list
Section titled “PtyService.list”def list() -> ListResult[ProcessInfo]PtyService.start
Section titled “PtyService.start”def start(command: Optional[str] = None, *, cols: int = 80, rows: int = 24, cwd: Optional[str] = None, env: Optional[Mapping[str, str]] = None, name: Optional[str] = None) -> ProcessHandleStart a detached PTY process.
AsyncPtyService
Section titled “AsyncPtyService”class AsyncPtyService()PTY convenience namespace.
AsyncPtyService.__init__
Section titled “AsyncPtyService.__init__”def __init__(process: AsyncProcessService) -> NoneAsyncPtyService.start
Section titled “AsyncPtyService.start”async def start(command: Optional[str] = None, *, cols: int = 80, rows: int = 24, cwd: Optional[str] = None, env: Optional[Mapping[str, str]] = None, name: Optional[str] = None) -> AsyncProcessHandleStart a detached PTY process.
AsyncPtyService.connect
Section titled “AsyncPtyService.connect”def connect(process_id: str) -> AsyncProcessHandleCreate a bound PTY handle.
AsyncPtyService.list
Section titled “AsyncPtyService.list”async def list() -> ListResult[ProcessInfo]AsyncPtyService.delete
Section titled “AsyncPtyService.delete”async def delete(process_id: str) -> NoneSession
Section titled “Session”class Session()One persistent shell whose commands run one at a time, in order.
Session.__init__
Section titled “Session.__init__”def __init__(impl: AsyncSession, bridge: SyncBridge) -> NoneSession.sandbox_id
Section titled “Session.sandbox_id”@propertydef sandbox_id() -> strSession.id
Section titled “Session.id”@propertydef id() -> strSession.delete
Section titled “Session.delete”def delete() -> NoneEnd this shell and remove it and all its commands.
Session.from_json
Section titled “Session.from_json”@classmethoddef from_json(value: Mapping[str, object]) -> SessionRehydrate an unbound identity without making a request.
Session.get
Section titled “Session.get”def get() -> ProcessInfoFetch session metadata, including the shell’s live cwd.
Session.run
Section titled “Session.run”def run(command: str, *, stdin: StdinMode = 'closed', timeout: Optional[float] = None, execution_timeout: Optional[float] = None, name: Optional[str] = None, keep_logs: Optional[KeepLogs] = None) -> ProcessResultRun a command in this shell and collect output; timeouts are seconds.
Session.start
Section titled “Session.start”def start(command: str, *, stdin: StdinMode = 'closed', execution_timeout: Optional[float] = None, name: Optional[str] = None, keep_logs: Optional[KeepLogs] = None) -> ProcessHandleQueue a command and return its handle without waiting for exit.
Session.to_json
Section titled “Session.to_json”def to_json() -> _SessionIdentityReturn a JSON-safe identity for process.connect_session().
AsyncSession
Section titled “AsyncSession”class AsyncSession()One persistent shell whose commands run one at a time, in order.
Directory changes, exports and functions carry over between commands.
Set cwd and env when calling process.create_session(). Interrupt a
running command with handle.kill(signal="INT"); the session survives.
Sessions do not survive a sandbox stop/start. On Windows, interrupts stop
external programs but cannot interrupt PowerShell loops or cmdlets, and
commands cannot take stdin="open". After set -x or set -v in a
session, later commands’ stderr also traces the daemon’s own lines that
run each command.
AsyncSession.__init__
Section titled “AsyncSession.__init__”def __init__(sandbox_id: str, session_id: str, transport: Optional[AsyncTransport] = None) -> NoneAsyncSession.to_json
Section titled “AsyncSession.to_json”def to_json() -> _SessionIdentityReturn a JSON-safe identity for process.connect_session().
AsyncSession.from_json
Section titled “AsyncSession.from_json”@classmethoddef from_json(value: Mapping[str, object]) -> AsyncSessionRehydrate an unbound identity without making a request.
AsyncSession.run
Section titled “AsyncSession.run”async def run(command: str, *, stdin: StdinMode = 'closed', timeout: Optional[float] = None, execution_timeout: Optional[float] = None, name: Optional[str] = None, keep_logs: Optional[KeepLogs] = None) -> ProcessResultRun a command in this shell and collect output; timeouts are seconds.
timeout bounds the caller’s wait without stopping the command;
execution_timeout stops the command without ending the session. A
command that has not stopped 5 s after its timeout (the shell could
not interrupt it and it runs no process to kill) ends the session
instead. In dash, BusyBox sh and mksh an interrupt leaves only the
innermost shell function or sourced file, as it does in bash older than
4.4 (macOS’s /bin/bash) when a DEBUG trap is set.
AsyncSession.start
Section titled “AsyncSession.start”async def start(command: str, *, stdin: StdinMode = 'closed', execution_timeout: Optional[float] = None, name: Optional[str] = None, keep_logs: Optional[KeepLogs] = None) -> AsyncProcessHandleQueue a command and return its handle without waiting for exit.
Interrupt it with handle.kill(signal="INT"); the shell survives.
execution_timeout is a server-side deadline in seconds; the clock
starts when the command starts, after any queued commands ahead of it.
AsyncSession.get
Section titled “AsyncSession.get”async def get() -> ProcessInfoFetch session metadata, including the shell’s live cwd.
AsyncSession.delete
Section titled “AsyncSession.delete”async def delete() -> NoneEnd this shell and remove it and all its commands.
ProcessInfo
Section titled “ProcessInfo”@dataclass(frozen=True)class ProcessInfo()Serializable daemon process DTO.
Attributes:
idstrkindProcessInfoKindstateProcessStatenameOptional[str] = NonepidOptional[int] = Nonesystembool = Falsesession_idOptional[str] = Noneshell_commandOptional[str] = NoneargvOptional[List[str]] = NonecodeOptional[str] = NonelanguageOptional[str] = NoneshellOptional[str] = Noneresolved_shellOptional[str] = NoneloginOptional[bool] = NonecwdOptional[str] = NoneuserOptional[str] = NonestdinOptional[ProcessStdinMode] = Noneexecution_timeoutOptional[float] = NoneterminalOptional[TerminalSize] = Nonekeep_logsOptional[ProcessKeepLogs] = Noneexit_codeOptional[int] = NonesignalOptional[str] = NonereasonOptional[WaitReason] = Nonecreated_atOptional[str] = Nonestarted_atOptional[str] = Noneexited_atOptional[str] = Nonetruncated_headbool = Falsefirst_available_cursorOptional[str] = Nonelast_cursorOptional[str] = Noneraw_kindOptional[str] = Noneraw_stateOptional[str] = Noneraw_stdinOptional[str] = Noneraw_keep_logsOptional[str] = Noneraw_reasonOptional[str] = None
ProcessHandleRef
Section titled “ProcessHandleRef”@dataclass(frozen=True)class ProcessHandleRef()JSON-safe process handle identity.
Attributes:
sandbox_idstrprocess_idstrkindOptional[ProcessKind] = None
WaitResult
Section titled “WaitResult”@dataclass(frozen=True)class WaitResult()Result returned by process wait.
Attributes:
exit_codeOptional[int] = NonesignalOptional[str] = NonereasonOptional[WaitReason] = Noneraw_reasonOptional[str] = None
LogFrame
Section titled “LogFrame”@dataclass(frozen=True)class LogFrame()One replayable process ledger frame.
Attributes:
cursorstrchannelstrdatastrtimestampOptional[int] = None
LogPage
Section titled “LogPage”@dataclass(frozen=True)class LogPage()A cursor-addressed process log page.
Attributes:
itemsList[LogFrame]next_cursorOptional[str] = Nonetruncated_headbool = Falsefirst_available_cursorOptional[str] = None
ProcessResult
Section titled “ProcessResult”@dataclass(frozen=True)class ProcessResult()Process run result with collected output.
Attributes:
process_idstrexit_codeOptional[int]signalOptional[str]reasonOptional[WaitReason]stdoutstr = ”stderrstr = ”outputstr = ”raw_reasonOptional[str] = None
TerminalSize
Section titled “TerminalSize”@dataclass(frozen=True)class TerminalSize()PTY terminal dimensions.
Attributes:
colsintrowsint
ProcessKind
Section titled “ProcessKind”ProcessKind = Literal['exec', 'pty', 'code', 'session']ProcessInfoKind
Section titled “ProcessInfoKind”ProcessInfoKind = Literal['exec', 'pty', 'code', 'session', 'unknown']ProcessStateFilter
Section titled “ProcessStateFilter”ProcessStateFilter = Literal['running', 'terminal', 'all']ProcessState
Section titled “ProcessState”ProcessState = Literal['starting', 'provisioning', 'running', 'terminal', 'unknown']KeepLogs
Section titled “KeepLogs”KeepLogs = Literal['until_cleanup', 'on_exit_ttl', 'none']StdinMode
Section titled “StdinMode”StdinMode = Literal['closed', 'open']ProcessKeepLogs
Section titled “ProcessKeepLogs”ProcessKeepLogs = Literal['until_cleanup', 'on_exit_ttl', 'none', 'unknown']ProcessStdinMode
Section titled “ProcessStdinMode”ProcessStdinMode = Literal['closed', 'open', 'unknown']WaitReason
Section titled “WaitReason”WaitReason = Literal['exited', 'signaled', 'timed_out', 'lost', 'failed', 'unknown']