datarobot_genai.drtools.core.sandbox.base
base
Core types for the sandbox abstraction.
Defines the :class:Sandbox Protocol, the :class:SandboxResult and
:class:SandboxSecurityContext data models, and the exception hierarchy
(:class:SandboxError, :class:SandboxTimeout).
SandboxError
Bases: Exception
Base error raised when sandboxed execution fails.
Subclassed by :class:SandboxTimeout (timeout) and
:class:SandboxInfraError (provisioning/transport failure).
Carries optional structured detail so observability can classify the
failure without re-parsing the message string: exit_code (the
container/process exit status, e.g. 137 for an OOM kill) and
stderr (captured standard error, scanned for OOM/timeout markers).
Source code in datarobot_genai/drtools/core/sandbox/base.py
SandboxTimeout
Bases: SandboxError
Raised when sandboxed execution exceeds the configured timeout.
Source code in datarobot_genai/drtools/core/sandbox/base.py
SandboxInfraError
Bases: SandboxError
Raised when the sandbox cannot be provisioned or reached.
Distinguishes an infrastructure/transport failure before user code runs (image pull failure, workload-api unreachable) from a user-code failure, so the two are not conflated in the failure taxonomy.
Source code in datarobot_genai/drtools/core/sandbox/base.py
SandboxResult
dataclass
Result of a successful sandboxed execution.
Attributes
stdout
Captured standard output.
stderr
Captured standard error.
return_value
Value the user code assigned to the magic _return variable, if any.
duration_s
Wall-clock execution duration in seconds.
exit_code
Process exit code (0 for success).
Source code in datarobot_genai/drtools/core/sandbox/base.py
SandboxSecurityContext
Bases: BaseModel
Container security context applied to sandboxed workloads.
Mirrors the SecurityContext schema in the DataRobot workload-api
(see workload_api/schemas/containers.py:169).
Defaults are deliberately the most restrictive settings that a non-admin
user is allowed to apply: read-only root filesystem, drop all Linux
capabilities, RuntimeDefault seccomp profile, and no privilege
escalation.
Source code in datarobot_genai/drtools/core/sandbox/base.py
to_workload_api_dict
Serialize to the camelCase shape accepted by workload-api.
Returns
dict
A dict with keys readOnlyRootFilesystem,
allowPrivilegeEscalation, capabilities (with add/drop
sublists), and seccompProfile (with type). Empty
capability lists are omitted; capabilities and
seccompProfile are omitted entirely when they would be empty.
Source code in datarobot_genai/drtools/core/sandbox/base.py
Sandbox
Bases: Protocol
Protocol for sandboxed Python code execution.
The production implementation is :class:DataRobotWorkloadSandbox
(runs in the DataRobot workload-api). A local-Docker dev/test
implementation is planned as a follow-up.
Source code in datarobot_genai/drtools/core/sandbox/base.py
run
async
run(code: str, *, inputs: dict[str, Any] | None = None, externals: dict[str, Any] | None = None, timeout_s: float = 30.0) -> SandboxResult
Execute code in an isolated environment and return the result.
Parameters
code
Python source to execute. May assign to a magic _return
variable to communicate a return value back to the caller.
inputs
Mapping bound as inputs in the executing namespace. Must be
JSON-serializable for remote backends.
externals
Mapping bound as externals in the executing namespace for
CodeMode-style tool injection. Most implementations do not yet
support this and will raise NotImplementedError.
timeout_s
Wall-clock timeout in seconds.
Returns
SandboxResult
stdout/stderr capture, the _return value, duration, and
exit code.
Raises
SandboxTimeout
When execution exceeds timeout_s.
SandboxError
When the sandbox itself fails or the user code raises.