Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
Daytona Sandbox Tools
Run shell commands, execute Python, and manage files inside a Daytona sandbox. Daytona provides isolated, ephemeral compute environments suitable for agent-driven code execution.
Three tools are provided so you can pick what the agent actually needs:
DaytonaExecTool— run a shell command (sandbox.process.exec).DaytonaPythonTool— run a Python script (sandbox.process.code_run).DaytonaFileTool— read / write / list / delete files (sandbox.fs.*).
Installation
uv add "crewai-tools[daytona]"
# or
pip install "crewai-tools[daytona]"
Set the API key:
export DAYTONA_API_KEY="..."
DAYTONA_API_URL and DAYTONA_TARGET are also respected if set.
Sandbox lifecycle
All three tools share the same lifecycle controls from DaytonaBaseTool:
| Mode | When the sandbox is created | When it is deleted |
|---|---|---|
Ephemeral (default, persistent=False) |
On every _run call |
At the end of that same call |
Persistent (persistent=True) |
Lazily on first use | At process exit (via atexit), or manually via tool.close() |
Attach (sandbox_id="…") |
Never — the tool attaches to an existing sandbox | Never — the tool will not delete a sandbox it did not create |
Ephemeral mode is the safe default: nothing leaks if the agent forgets to clean up. Use persistent mode when you want filesystem state or installed packages to carry across steps — this is typical when pairing DaytonaFileTool with DaytonaExecTool.
Examples
One-shot Python execution (ephemeral)
from crewai_tools import DaytonaPythonTool
tool = DaytonaPythonTool()
result = tool.run(code="print(sum(range(10)))")
Multi-step shell session (persistent)
from crewai_tools import DaytonaExecTool, DaytonaFileTool
exec_tool = DaytonaExecTool(persistent=True)
file_tool = DaytonaFileTool(persistent=True)
# Agent writes a script, then runs it — but each tool keeps its OWN persistent
# sandbox. To share the *same* sandbox across two tools, create and use the
# first tool, then read its `active_sandbox_id` and pass it to the second:
# exec_tool.run(command="pip install httpx")
# file_tool = DaytonaFileTool(sandbox_id=exec_tool.active_sandbox_id)
Attach to an existing sandbox
from crewai_tools import DaytonaExecTool
tool = DaytonaExecTool(sandbox_id="my-long-lived-sandbox")
Custom create params
Pass Daytona's CreateSandboxFromSnapshotParams kwargs via create_params:
tool = DaytonaExecTool(
persistent=True,
create_params={
"language": "python",
"env_vars": {"MY_FLAG": "1"},
"labels": {"owner": "crewai-agent"},
},
)
Tool arguments
DaytonaExecTool
command: str— shell command to run.cwd: str | None— working directory.env: dict[str, str] | None— extra env vars for this command.timeout: int | None— seconds.
DaytonaPythonTool
code: str— Python source to execute.argv: list[str] | None— argv forwarded viaCodeRunParams.env: dict[str, str] | None— env vars forwarded viaCodeRunParams.timeout: int | None— seconds.
DaytonaFileTool
action: one ofread,write,append,list,delete,mkdir,info,exists,move,find,search,chmod,replace.path: str | None— absolute path inside the sandbox. Required for all actions exceptreplace.content: str | None— required forappend; optional forwrite.binary: bool— ifTrue,contentis base64 on write / returned as base64 on read.recursive: bool— fordelete, removes directories recursively.mode: str | None— formkdir(defaults to"0755") or forchmod(e.g."755").destination: str | None— required formove.pattern: str | None— required forfind(content grep),search(filename glob), andreplace.replacement: str | None— required forreplace.paths: list[str] | None— required forreplace; list of files to operate on.owner: str | None/group: str | None— forchmod. Pass at least one ofmode,owner, orgroup.