Executors API Reference
Bases: Protocol
Protocol for objects that execute file-based skill scripts.
Implement this to run skill scripts somewhere other than a local
subprocess — a container sandbox, a remote worker, or an in-process
debugger. Pass the instance as script_executor to SkillsDirectory
or discover_skills.
Example
from typing import Any
from pydantic_ai_skills import SkillScript, SkillsDirectory
class EchoExecutor:
async def run(
self,
script: SkillScript,
args: dict[str, Any] | None = None,
ctx: Any | None = None,
) -> Any:
return f'Would run {script.uri} with {args}'
directory = SkillsDirectory(path='./skills', script_executor=EchoExecutor())
Source code in pydantic_ai_skills/executors.py
26 27 28 29 30 31 32 33 34 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 | |
run
async
run(script: SkillScript, args: dict[str, Any] | None = None, ctx: Any | None = None) -> Any
Run a skill script.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script
|
SkillScript
|
The script to run. For file-based scripts, |
required |
args
|
dict[str, Any] | None
|
Named arguments for the script, or None. |
None
|
ctx
|
Any | None
|
Optional run context, forwarded from the agent run. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The script output. Executors used with |
Any
|
should return a string. |
Source code in pydantic_ai_skills/executors.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
Bases: SkillScriptExecutor
Execute skill scripts using local subprocesses.
Executes file-based scripts as subprocesses with args passed as command-line named arguments. Dictionary keys are used exactly as provided (e.g., {"max-papers": 5} becomes --max-papers 5). A shebang line is used first when present and resolvable, then suffix-based fallback is used for compatibility. Other files are executed directly. Uses anyio.open_process with custom output collection and timeout handling for async-compatible subprocess execution.
Note
All scripts must accept named arguments. Positional arguments are not supported.
Attributes:
| Name | Type | Description |
|---|---|---|
timeout |
Execution timeout in seconds. |
Source code in pydantic_ai_skills/local.py
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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
run
async
run(script: SkillScript, args: dict[str, Any] | None = None, ctx: Any | None = None) -> Any
Run a skill script locally using subprocess.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script
|
SkillScript
|
The script to run. |
required |
args
|
dict[str, Any] | None
|
Named arguments as a dictionary. Boolean True emits flag only, False/None omits it, lists repeat the flag for each item, other types convert to string. |
None
|
ctx
|
Any | None
|
Optional run context used to merge context-provided env_vars into the subprocess environment. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Combined stdout and stderr output. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the script has no URI configured. |
RuntimeError
|
If execution fails to start. |
TimeoutError
|
If execution exceeds the configured timeout. |
Source code in pydantic_ai_skills/local.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
Bases: SkillScriptExecutor
Wraps a callable in a script executor interface.
Allows users to provide custom execution logic for file-based scripts instead of using subprocess execution. Useful for remote execution, sandboxed execution, or other custom scenarios.
Example
from pydantic_ai_skills import CallableSkillScriptExecutor, SkillsDirectory
async def my_executor(script, args=None):
# Custom execution logic - script.uri contains the file path
return f"Executed {script.name} at {script.uri} with {args}"
executor = CallableSkillScriptExecutor(func=my_executor)
directory = SkillsDirectory(path="./skills", script_executor=executor)
Source code in pydantic_ai_skills/local.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
run
async
run(script: SkillScript, args: dict[str, Any] | None = None, ctx: Any | None = None) -> Any
Run using the wrapped callable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script
|
SkillScript
|
The script to run. |
required |
args
|
dict[str, Any] | None
|
Named arguments as a dictionary. |
None
|
ctx
|
Any | None
|
Optional run context passed to wrapped callable when supported. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Script output (can be any type like str, dict, etc.). |
Source code in pydantic_ai_skills/local.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
Execute file-based skill scripts inside an OpenSandbox container.
Attributes:
| Name | Type | Description |
|---|---|---|
timeout |
Per-script execution timeout in seconds. |
Source code in pydantic_ai_skills/sandboxes/opensandbox.py
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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
run
async
run(script: SkillScript, args: dict[str, Any] | None = None, ctx: Any | None = None) -> Any
Run a skill script inside an OpenSandbox container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script
|
SkillScript
|
The script to run; |
required |
args
|
dict[str, Any] | None
|
Named arguments, marshalled with the same rules as
|
None
|
ctx
|
Any | None
|
Unused; accepted for protocol compatibility. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Combined stdout and stderr, formatted like local execution. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the script has no URI configured. |
Source code in pydantic_ai_skills/sandboxes/opensandbox.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
aclose
async
aclose() -> None
Kill the reused sandbox, if one is alive.
Source code in pydantic_ai_skills/sandboxes/opensandbox.py
309 310 311 312 313 314 315 316 317 318 | |
Execute file-based skill scripts inside a LocalSandbox virtual filesystem.
LocalSandbox has no CPython binary on PATH, so there are two paths:
shell scripts run through abash, and .py scripts run through
aexecute_python (Pyodide) with an injected sys.argv and
runpy.run_path(..., run_name='__main__'), so argparse and
if __name__ == '__main__' behave normally.
Pyodide ships a subset of the ecosystem and has no sockets or subprocesses, so scripts needing third-party wheels or network access will fail here.
Attributes:
| Name | Type | Description |
|---|---|---|
workdir |
Directory inside the sandbox that the skill folder is staged into. |
Source code in pydantic_ai_skills/sandboxes/localsandbox.py
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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
run
async
run(script: SkillScript, args: dict[str, Any] | None = None, ctx: Any | None = None) -> Any
Run a skill script inside a LocalSandbox virtual filesystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script
|
SkillScript
|
The script to run; |
required |
args
|
dict[str, Any] | None
|
Named arguments, marshalled with the same rules as
|
None
|
ctx
|
Any | None
|
Unused; accepted for protocol compatibility. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Combined stdout and stderr, formatted like local execution. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the script has no URI, or its type is unsupported here. |
Source code in pydantic_ai_skills/sandboxes/localsandbox.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
close
close() -> None
Close the reused sandbox, if one is alive.
Source code in pydantic_ai_skills/sandboxes/localsandbox.py
351 352 353 354 355 356 357 | |