mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-07-05 15:09:22 +00:00
* feat: adopt directory-based docs versioning with Edge channel Switch docs.crewai.com from navigation-only versioning (every version selector entry rendered the same docs/<lang>/* source files) to Mintlify's directory-based versioning so each version selector entry renders its own snapshot. Add an "Edge" channel under docs/edge/<lang>/* that always reflects main HEAD for unreleased work, eliminating pre-release leakage onto frozen release labels. External links to canonical /<lang>/* URLs are preserved via wildcard redirects that always land on the current default version. Layout: - docs/edge/<lang>/* rolling source (you edit here) - docs/edge/enterprise-api.*.yaml - docs/v<X.Y.Z>/<lang>/* frozen, immutable snapshots - docs/v<X.Y.Z>/enterprise-api.*.yaml - docs/images/ shared, append-only - docs/docs.json nav + redirects URLs follow the Mintlify-idiomatic shape: /edge/<lang>/<page> for Edge, /v<X.Y.Z>/<lang>/<page> for every frozen snapshot. The wildcard redirects /<lang>/:slug* -> /<default>/<lang>/:slug* keep stale links working, and every freeze rewrites them (plus all per-section/per-page redirects) so destinations always resolve to the current default without depending on a second redirect hop. Release flow integration (devtools release): - New module crewai_devtools.docs_versioning.freeze() materialises docs/v<X.Y.Z>/ from docs/edge/, rewrites openapi: refs inside the snapshot, inserts the version into every language block in docs.json, and refreshes all redirect destinations. - _update_docs_and_create_pr() in cli.py now calls that freeze during Phase 2 of devtools release. Edge changelogs are updated first (so the snapshot freeze picks them up), then the snapshot is staged alongside docs.json, branched as docs/freeze-v<X.Y.Z>, and the PR is titled [docs-freeze] docs: snapshot and changelog for v<X.Y.Z> — the title prefix the new CI guard reads. - The PR still gates tag, GitHub release, PyPI publish, and the enterprise release as before; no new PRs are added. - Pre-releases (1.X.YaN, 1.X.YbN, ...) skip the snapshot — they ride Edge — and the docs PR title omits the [docs-freeze] prefix. - docs_check (AI-generated docs scaffolding) writes to docs/edge/<lang>/* so newly-generated unreleased docs land in Edge and never accidentally touch a frozen snapshot. Migration scripts (one-shot): - scripts/docs/freeze_historical_versions.py reconstructs all 16 historical snapshots (v1.10.0 .. v1.14.7) from git tags via git archive | tar, rewriting openapi: MDX refs so each snapshot reads its own enterprise-api YAML rather than the live one. - scripts/docs/prefix_version_paths.py one-shot-migrates docs.json: rewrites every page path in 16 versioned blocks to point under docs/v<X.Y.Z>/, inserts a new Edge entry per language, tags v1.14.7 as Latest (default), prunes pages whose target file doesn't exist in the snapshot (e.g. docs/ar/ didn't exist before v1.12.0), and writes the wildcard + per-section redirects. - scripts/docs/freeze_current_edge.py is now a thin CLI wrapper around docs_versioning.freeze for manual one-off freezes (e.g. retroactively snapshotting a forgotten release). CI guards (.github/workflows/docs-snapshots.yml): - Frozen snapshots under docs/v[0-9]*/ are immutable; only PRs whose title contains [docs-freeze] (i.e. release-cut PRs generated by devtools release or the manual wrapper) may modify them. - Images under docs/images/ are append-only since snapshots share a single image directory. Deleting or renaming an image breaks every historical snapshot that still references it. Restored docs/images/crewai-otel-export.png from PR #3673; it was deleted in PR #4908 but v1.10.0 / v1.10.1 snapshots still reference it. Restoring instead of editing the snapshots preserves historical rendering fidelity and validates the new append-only rule retroactively. Tests: - lib/devtools/tests/test_docs_versioning.py covers the freeze: file copy, openapi rewrite, version insertion, default demotion, redirect upserts, per-section redirect rewriting, idempotency, and invalid inputs. Verified locally with mintlify broken-links: 0 broken links across the full site (Edge + 16 frozen versions, 4 locales). AGENTS.md (repo root) is the contributor guide for the new model; RELEASING.md is the release-cut runbook; README's Contribution section links to both. Co-authored-by: Cursor <cursoragent@cursor.com> * style: resolve linter issues --------- Co-authored-by: Cursor <cursoragent@cursor.com>
231 lines
9.1 KiB
Plaintext
231 lines
9.1 KiB
Plaintext
---
|
|
title: Daytona Sandbox Tools
|
|
description: Run shell commands, execute Python, and manage files inside isolated [Daytona](https://www.daytona.io/) sandboxes.
|
|
icon: box
|
|
mode: "wide"
|
|
---
|
|
|
|
# Daytona Sandbox Tools
|
|
|
|
## Description
|
|
|
|
The Daytona sandbox tools give CrewAI agents access to isolated, ephemeral compute environments powered by [Daytona](https://www.daytona.io/). Three tools are available so you can give an agent exactly the capabilities it needs:
|
|
|
|
- **`DaytonaExecTool`** — run any shell command inside a sandbox.
|
|
- **`DaytonaPythonTool`** — execute a block of Python source code inside a sandbox.
|
|
- **`DaytonaFileTool`** — read, write, append, list, delete, and inspect files inside a sandbox; also supports `move`, `find` (content grep), `search` (filename glob), `chmod` (permissions), `replace` (bulk find-and-replace), and `exists`.
|
|
|
|
All three tools share the same sandbox lifecycle controls, so you can mix and match them while keeping state in a single persistent sandbox.
|
|
|
|
## Installation
|
|
|
|
```shell
|
|
uv add "crewai-tools[daytona]"
|
|
# or
|
|
pip install "crewai-tools[daytona]"
|
|
```
|
|
|
|
Set your API key:
|
|
|
|
```shell
|
|
export DAYTONA_API_KEY="your-api-key"
|
|
```
|
|
|
|
`DAYTONA_API_URL` and `DAYTONA_TARGET` are also respected if set.
|
|
|
|
## Sandbox Lifecycle
|
|
|
|
All three tools inherit lifecycle controls from `DaytonaBaseTool`:
|
|
|
|
| Mode | How to enable | Sandbox created | Sandbox deleted |
|
|
|------|--------------|-----------------|-----------------|
|
|
| **Ephemeral** (default) | `persistent=False` (default) | 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="<id>"` | Never — 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 multiple tool calls — this is typical when pairing `DaytonaFileTool` with `DaytonaExecTool`.
|
|
|
|
## Examples
|
|
|
|
### One-shot Python execution (ephemeral)
|
|
|
|
```python Code
|
|
from crewai_tools import DaytonaPythonTool
|
|
|
|
tool = DaytonaPythonTool()
|
|
result = tool.run(code="print(sum(range(10)))")
|
|
print(result)
|
|
# {"exit_code": 0, "result": "45\n", "artifacts": ExecutionArtifacts(stdout="45\n", charts=[])}
|
|
```
|
|
|
|
### Multi-step shell session (persistent)
|
|
|
|
```python Code
|
|
from crewai_tools import DaytonaExecTool, DaytonaFileTool
|
|
|
|
# Create the persistent sandbox via the first tool, then attach the second
|
|
# tool to it so both share state (installed packages, files, env vars).
|
|
exec_tool = DaytonaExecTool(persistent=True)
|
|
exec_tool.run(command="pip install httpx -q")
|
|
file_tool = DaytonaFileTool(sandbox_id=exec_tool.active_sandbox_id)
|
|
|
|
file_tool.run(
|
|
action="write",
|
|
path="workspace/script.py",
|
|
content="import httpx; print(f'httpx loaded, version {httpx.__version__}')",
|
|
)
|
|
exec_tool.run(command="python workspace/script.py")
|
|
```
|
|
|
|
<Note>
|
|
By default, each tool with `persistent=True` lazily creates its **own** sandbox on first use. The pattern above shares a single sandbox across multiple tools by reading the first tool's `active_sandbox_id` after a `.run()` call and passing it to the others via `sandbox_id=...`. With `persistent=False` (the default), every `.run()` call gets a fresh sandbox that's deleted at the end of that call.
|
|
</Note>
|
|
|
|
### Attach to an existing sandbox
|
|
|
|
```python Code
|
|
from crewai_tools import DaytonaExecTool
|
|
|
|
tool = DaytonaExecTool(sandbox_id="my-long-lived-sandbox")
|
|
result = tool.run(command="ls workspace")
|
|
```
|
|
|
|
### Custom sandbox parameters
|
|
|
|
Pass Daytona's `CreateSandboxFromSnapshotParams` kwargs via `create_params`:
|
|
|
|
```python Code
|
|
from crewai_tools import DaytonaExecTool
|
|
|
|
tool = DaytonaExecTool(
|
|
persistent=True,
|
|
create_params={
|
|
"language": "python",
|
|
"env_vars": {"MY_FLAG": "1"},
|
|
"labels": {"owner": "crewai-agent"},
|
|
},
|
|
)
|
|
```
|
|
|
|
### Searching, moving, and modifying files
|
|
|
|
```python Code
|
|
from crewai_tools import DaytonaFileTool
|
|
|
|
file_tool = DaytonaFileTool(persistent=True)
|
|
|
|
# Find every TODO in the source tree (grep file contents recursively)
|
|
file_tool.run(action="find", path="workspace/src", pattern="TODO:")
|
|
|
|
# Find all Python files (glob match on filenames)
|
|
file_tool.run(action="search", path="workspace", pattern="*.py")
|
|
|
|
# Make a script executable
|
|
file_tool.run(action="chmod", path="workspace/run.sh", mode="755")
|
|
|
|
# Rename or move a file
|
|
file_tool.run(
|
|
action="move",
|
|
path="workspace/draft.md",
|
|
destination="workspace/final.md",
|
|
)
|
|
|
|
# Bulk find-and-replace across multiple files
|
|
file_tool.run(
|
|
action="replace",
|
|
paths=["workspace/src/a.py", "workspace/src/b.py"],
|
|
pattern="old_function",
|
|
replacement="new_function",
|
|
)
|
|
|
|
# Quick existence check before a destructive op
|
|
file_tool.run(action="exists", path="workspace/cache.db")
|
|
```
|
|
|
|
### Agent integration
|
|
|
|
```python Code
|
|
from crewai import Agent, Task, Crew
|
|
from crewai_tools import DaytonaExecTool, DaytonaPythonTool, DaytonaFileTool
|
|
|
|
exec_tool = DaytonaExecTool(persistent=True)
|
|
python_tool = DaytonaPythonTool(persistent=True)
|
|
file_tool = DaytonaFileTool(persistent=True)
|
|
|
|
coder = Agent(
|
|
role="Sandbox Engineer",
|
|
goal="Write and run code in an isolated environment",
|
|
backstory="An engineer who uses Daytona sandboxes to safely execute code and manage files.",
|
|
tools=[exec_tool, python_tool, file_tool],
|
|
verbose=True,
|
|
)
|
|
|
|
task = Task(
|
|
description="Write a Python script that prints the first 10 Fibonacci numbers, save it to workspace/fib.py, and run it.",
|
|
expected_output="The first 10 Fibonacci numbers printed to stdout.",
|
|
agent=coder,
|
|
)
|
|
|
|
crew = Crew(agents=[coder], tasks=[task])
|
|
result = crew.kickoff()
|
|
```
|
|
|
|
## Parameters
|
|
|
|
### Shared (`DaytonaBaseTool`)
|
|
|
|
All three tools accept these parameters at initialization:
|
|
|
|
| Parameter | Type | Default | Description |
|
|
|-----------|------|---------|-------------|
|
|
| `api_key` | `str \| None` | `$DAYTONA_API_KEY` | Daytona API key. Falls back to the `DAYTONA_API_KEY` env var. |
|
|
| `api_url` | `str \| None` | `$DAYTONA_API_URL` | Daytona API URL override. |
|
|
| `target` | `str \| None` | `$DAYTONA_TARGET` | Daytona target region. |
|
|
| `persistent` | `bool` | `False` | Reuse one sandbox across all calls and delete it at process exit. |
|
|
| `sandbox_id` | `str \| None` | `None` | Attach to an existing sandbox by id or name. |
|
|
| `create_params` | `dict \| None` | `None` | Extra kwargs forwarded to `CreateSandboxFromSnapshotParams` (e.g. `language`, `env_vars`, `labels`). |
|
|
| `sandbox_timeout` | `float` | `60.0` | Timeout in seconds for sandbox create/delete operations. |
|
|
|
|
### `DaytonaExecTool`
|
|
|
|
| Parameter | Type | Required | Description |
|
|
|-----------|------|----------|-------------|
|
|
| `command` | `str` | ✓ | Shell command to execute. |
|
|
| `cwd` | `str \| None` | | Working directory inside the sandbox. |
|
|
| `env` | `dict[str, str] \| None` | | Extra environment variables for this command. |
|
|
| `timeout` | `int \| None` | | Maximum seconds to wait for the command. |
|
|
|
|
### `DaytonaPythonTool`
|
|
|
|
| Parameter | Type | Required | Description |
|
|
|-----------|------|----------|-------------|
|
|
| `code` | `str` | ✓ | Python source code to execute. |
|
|
| `argv` | `list[str] \| None` | | Argument vector forwarded via `CodeRunParams`. |
|
|
| `env` | `dict[str, str] \| None` | | Environment variables forwarded via `CodeRunParams`. |
|
|
| `timeout` | `int \| None` | | Maximum seconds to wait for execution. |
|
|
|
|
### `DaytonaFileTool`
|
|
|
|
| Parameter | Type | Required | Description |
|
|
|-----------|------|----------|-------------|
|
|
| `action` | `str` | ✓ | One of: `read`, `write`, `append`, `list`, `delete`, `mkdir`, `info`, `exists`, `move`, `find`, `search`, `chmod`, `replace`. |
|
|
| `path` | `str \| None` | ✓ for all actions except `replace` | Absolute path inside the sandbox. |
|
|
| `content` | `str \| None` | ✓ for `append` | Content to write or append. |
|
|
| `binary` | `bool` | | If `True`, `content` is base64 on write; returns base64 on read. |
|
|
| `recursive` | `bool` | | For `delete`: remove directories recursively. |
|
|
| `mode` | `str \| None` | | For `mkdir`: octal permissions for the new directory (defaults to `"0755"`). For `chmod`: octal permissions to apply to the target. |
|
|
| `destination` | `str \| None` | ✓ for `move` | Destination path for `move`. |
|
|
| `pattern` | `str \| None` | ✓ for `find`, `search`, `replace` | For `find`: substring matched against file CONTENTS. For `search`: glob matched against file NAMES (e.g. `*.py`). For `replace`: text to replace inside files. |
|
|
| `replacement` | `str \| None` | ✓ for `replace` | Replacement text for `pattern`. |
|
|
| `paths` | `list[str] \| None` | ✓ for `replace` | List of file paths in which to replace text. |
|
|
| `owner` | `str \| None` | | For `chmod`: new file owner. |
|
|
| `group` | `str \| None` | | For `chmod`: new file group. |
|
|
|
|
<Note>
|
|
For `chmod`, pass at least one of `mode`, `owner`, or `group` — any field left as `None` is left unchanged on the target.
|
|
</Note>
|
|
|
|
<Tip>
|
|
For files larger than a few KB, create the file first with `action="write"` and empty content, then send the body via multiple `action="append"` calls of ~4 KB each to stay within tool-call payload limits.
|
|
</Tip>
|