Skip to main content
All Python modules · Import and compatibility guidance

Provider data contracts

Execution statuses

Exports

Sandbox

Declare one lazy sandbox usable by managed ADK and LangGraph agents. A sandbox is a code-execution boundary, not a policy label. The backend returned by factory implements SandboxBackend.execute and owns the actual isolation guarantees. Legacy ADK executors remain ADK-only providers. Compilation never connects to provider infrastructure. Obtain this object from the owning Harnest API; its constructor includes runtime bindings. Fields (— means no declared default):

Sandbox.provider

Configure a portable provider; native ADK factories remain compatible. Provider-specific SDK settings belong in the factory. adapter_options configures only the native framework adapter, while JSON metadata and an optional network policy are forwarded to each request. A policy requires provider capability declarations.

Sandbox.to_adk_executor

Use ADK’s code_executor interface and native code/result event loop.

Sandbox.to_langchain_tool

Use LangGraph’s native tool loop with a lazy, typed execution tool.

Sandbox.build

Construct and validate a provider only when explicitly requested.

SandboxBackend

Execute in an isolated provider, never by evaluating code on the host. Implementations own isolation, deadlines, file handling, concurrency, resource cleanup, and user/session separation. Compilation never invokes this method.

SandboxBackend.execute

Execute Python under provider-enforced policy and return its output.

SandboxBudget

Request finite compute, memory, process, and scratch-space limits.
Fields (— means no declared default):

SandboxCancelledError

An execution lost its caller or its managed invocation authority.

SandboxContext

Supply optional invocation identity without exposing a native runtime. Providers may use this identity for tenant isolation. Direct adapter calls outside a runtime have no identity; providers requiring it must reject them.
Fields (— means no declared default):

SandboxExecutionError

A provider failed without exposing its private exception payload.

SandboxFile

Carry a file across an executor boundary without granting host access. String content is base64-encoded; bytes are the original file content. Providers own path validation and must never interpret names as host paths.
Fields (— means no declared default):

SandboxInputFilesUnsupportedError

A provider explicitly cannot materialize the requested input files.

SandboxNetworkMode

Describe the outbound network authority granted to one sandbox.

SandboxNetworkPolicy

Declare provider-enforced outbound access without assuming its mechanism. Allowlist entries are exact DNS names or IP literals. Providers must apply the policy to every connection and resolution, not only to the initial URL.
Fields (— means no declared default):

SandboxNetworkPolicy.none

Deny all outbound network connections.

SandboxNetworkPolicy.unrestricted

Permit outbound access, optionally retaining a private-network ceiling.

SandboxNetworkPolicy.allowlist

Permit exact hosts and optional destination ports only.

SandboxPolicyUnsupportedError

A provider cannot enforce an explicitly requested sandbox policy.

SandboxProvider

A portable backend that declares its enforceable sandbox policy.
Fields (— means no declared default):

SandboxProvider.execute

Execute Python under provider-enforced policy and return its output.

SandboxProviderCapabilities

Advertise network controls a provider enforces below agent code.
Fields (— means no declared default):

SandboxProviderCapabilities.require

Fail closed when this provider cannot enforce requested authority.

SandboxRequest

Describe one Python execution; the provider enforces its timeout.
Fields (— means no declared default):

SandboxResult

Return execution output without coupling providers to ADK or LangChain.
Fields (— means no declared default):

SandboxStatus

Provider-reported outcome; stderr alone does not mean execution failed.

cleanup_control

Admit resource release under a fresh finite deadline, never execution. Provider I/O must use remaining() as its transport timeout and check() before each side effect. This cooperative scope cannot interrupt arbitrary Python. Nested cleanup inherits the original cleanup deadline and cannot renew it.

control

Public provider controls, exported through harnest.sandbox.control.

control.execute

Scope deadlines independently while preserving call-wide cancellation.

control.cleanup

Admit resource release under a fresh finite deadline, never execution. Provider I/O must use remaining() as its transport timeout and check() before each side effect. This cooperative scope cannot interrupt arbitrary Python. Nested cleanup inherits the original cleanup deadline and cannot renew it.

control.current

Return the execution token inherited by native framework worker threads.