KubernetesPodSandbox¶
pydantic_ai_backends.backends.kubernetes.KubernetesPodSandbox
¶
Bases: BaseSandbox
Sandbox backed by a Kubernetes pod.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
str
|
container image to run. |
required |
namespace
|
str
|
K8s namespace to create the pod in. |
'default'
|
sandbox_id
|
str | None
|
identifier; used as a deterministic pod name suffix, sanitized to DNS-1123. Auto-generated if not provided. |
None
|
session_id
|
str | None
|
alias for |
None
|
mode
|
Literal['http', 'api']
|
|
'http'
|
port
|
int
|
port the in-pod exec server listens on (mode="http" only). |
DEFAULT_PORT
|
exec_token
|
str | None
|
shared secret sent in the |
None
|
pod_template
|
dict[str, Any] | None
|
optional dict — full pod spec body. If set, used
verbatim (with |
None
|
kube_config_path
|
str | None
|
path to a kubeconfig. If unset, falls back to
in-cluster config, then |
None
|
in_cluster
|
bool | None
|
force in-cluster vs out-of-cluster auth. |
None
|
startup_timeout
|
int
|
seconds to wait for |
DEFAULT_STARTUP_TIMEOUT
|
idle_timeout
|
int
|
passed through to |
3600
|
labels
|
dict[str, str] | None
|
extra labels merged into the pod metadata. |
None
|
env
|
dict[str, str] | None
|
extra environment variables for the container. |
None
|
delete_on_stop
|
bool
|
whether |
True
|
service_account_name
|
str
|
|
'default'
|
Lifecycle
__init__validates args and builds the in-memory client. It does not create the pod — callstart()(or letSessionManager.get_or_create()call it) to actually create.start()creates the pod and blocks until Ready.execute(),edit(),read(),write(),glob_info,grep_raw,ls_info: synchronous, talk to the pod (HTTP or pods/exec) and return.stop()deletes the pod (ifdelete_on_stop=True); idempotent; never raises.
Errors
- Constructor raises
ImportErrorif thekubernetesSDK is not installed (pip install pydantic-ai-backend[kubernetes]). start()raisesRuntimeErrorif the pod doesn't reachReadyinstartup_timeout.execute()never raises; runtime errors are surfaced asExecuteResponse(output="Error: ...", exit_code=1).
__init__(image, *, namespace='default', sandbox_id=None, session_id=None, mode='http', port=DEFAULT_PORT, exec_token=None, pod_template=None, kube_config_path=None, in_cluster=None, startup_timeout=DEFAULT_STARTUP_TIMEOUT, idle_timeout=3600, labels=None, env=None, delete_on_stop=True, service_account_name='default')
¶
start()
¶
Create the pod and wait for it to be Ready.