Daytona API¶
DaytonaSandbox¶
pydantic_ai_backends.backends.daytona.DaytonaSandbox
¶
Bases: BaseSandbox
Daytona cloud sandbox backend.
Creates an ephemeral Daytona sandbox for running commands and managing
files in an isolated cloud environment. Uses native Daytona file APIs
for read_bytes and write; all other file helpers are inherited
from :class:BaseSandbox (shell-based).
Source code in src/pydantic_ai_backends/backends/daytona.py
| Python | |
|---|---|
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
__init__(api_key=None, sandbox_id=None, work_dir='/home/daytona', startup_timeout=180)
¶
Initialise and start a Daytona sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | None
|
Daytona API key. Falls back to |
None
|
sandbox_id
|
str | None
|
Optional identifier (generated by Daytona if omitted). |
None
|
work_dir
|
str
|
Working directory inside the sandbox. |
'/home/daytona'
|
startup_timeout
|
int
|
Seconds to wait for the sandbox to become ready. |
180
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no API key is provided or found in environment. |
RuntimeError
|
If the sandbox fails to start within startup_timeout. |
Source code in src/pydantic_ai_backends/backends/daytona.py
execute(command, timeout=None)
¶
Execute a command inside the Daytona sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
Shell command string. |
required |
timeout
|
int | None
|
Maximum execution time in seconds ( |
None
|
Returns:
| Type | Description |
|---|---|
ExecuteResponse
|
class: |
Source code in src/pydantic_ai_backends/backends/daytona.py
read_bytes(path)
¶
Download file bytes via Daytona's native file API.
Source code in src/pydantic_ai_backends/backends/daytona.py
write(path, content)
¶
Upload a file via Daytona's native file API.
Creates parent directories automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Absolute path inside the sandbox. |
required |
content
|
str | bytes
|
File content (str or bytes). |
required |
Returns:
| Type | Description |
|---|---|
WriteResult
|
class: |
Source code in src/pydantic_ai_backends/backends/daytona.py
edit(path, old_string, new_string, replace_all=False)
¶
Edit a file by downloading it, replacing in Python and uploading it back.
Source code in src/pydantic_ai_backends/backends/daytona.py
exists(path)
¶
Check existence via Daytona's native file API.
Falls back to False for any error (missing file, permission
denied, transient API failure) — mirroring the broad exception
handling in :meth:read_bytes.
Source code in src/pydantic_ai_backends/backends/daytona.py
start()
¶
stop(purge=False)
¶
Delete the Daytona sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
purge
|
bool
|
Accepted for one signature across every sandbox, and it makes no difference here. Daytona has no "end it but keep the files" state this library can reattach to, so stopping is deleting - which is why the parameter is documented rather than quietly ignored. |
False
|
Source code in src/pydantic_ai_backends/backends/daytona.py
is_alive()
¶
Check if the sandbox is responsive.