Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Daytona Environment Sample

## Overview

A small data analysis agent that uses the `DaytonaEnvironment` with the
`EnvironmentToolset` to download public datasets and analyze them inside a
[Daytona](https://daytona.io) remote sandbox.

Instead of running on the local machine, all commands and file operations
execute in an isolated remote sandbox with internet access. Asked a question,
the agent downloads a public dataset (a GCS-hosted world population /
demographics dataset by default), installs `pandas` on demand, writes a short
analysis script, runs it, and reports the result — all without touching the
user's machine. This makes the sandbox a natural fit for running
model-generated code safely and keeping the host clean.

## Prerequisites

1. Install the `daytona` extra:

```bash
pip install google-adk[daytona]
```

1. Set your Daytona configuration. Get a server and API key by following the
Daytona installation guide (e.g. self-hosted or via Daytona Cloud).

If you are using Daytona Cloud, you only need to set:

```bash
export DAYTONA_API_KEY="your-api-key"
```

If you are using a self-hosted Daytona server, also set:

```bash
export DAYTONA_API_URL="your-api-url"
```

## Sample Inputs

- `Download the world demographics dataset and tell me which country has the largest population.`

The agent downloads the dataset, installs `pandas`, filters to country-level
rows, and finds the maximum. Expected: China (`CN`), ≈ 1.44 billion, just
ahead of India (`IN`) at ≈ 1.38 billion.

- `For the United States, what is the urban vs rural population split?`

A follow-up to the previous turn. Because the sandbox persists across the
session, the agent reuses the already-downloaded CSV and the installed
`pandas` — it only writes and runs a new script. Expected for `US`: urban
≈ 270.7 million vs rural ≈ 57.6 million (out of ≈ 331 million total).

- `Using https://storage.googleapis.com/cloud-samples-data/bigquery/us-states/us-states.csv, how many US states are listed?`

Demonstrates pointing the agent at your own dataset URL instead of the
default.

## Graph

```mermaid
graph TD
User -->|question| Agent[data_analysis_agent]
Agent -->|EnvironmentToolset| Sandbox[DaytonaEnvironment sandbox]
Sandbox -->|download / install / run| Agent
Agent -->|answer| User
```

## How To

The agent is a standalone `Agent` (no workflow graph) wired to a single
`EnvironmentToolset` whose `environment` is a `DaytonaEnvironment`:

```python
from google.adk.integrations.daytona import DaytonaEnvironment
from google.adk.tools.environment import EnvironmentToolset

EnvironmentToolset(
environment=DaytonaEnvironment(timeout=300),
)
```

- `timeout` bounds the sandbox lifetime in seconds.
- By default, it will spin up a sandbox from the built-in default Python snapshot.
If you want to use a custom Docker image instead, you can pass it to the
`image` parameter (e.g. `image="python:3.12"`).
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from . import agent
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""A data analysis agent that runs Python in a Daytona remote sandbox."""

from google.adk import Agent
from google.adk.integrations.daytona import DaytonaEnvironment
from google.adk.tools.environment import EnvironmentToolset

root_agent = Agent(
name="data_analysis_agent",
description=(
"A data analysis agent that downloads public datasets and analyzes"
" them inside a Daytona remote sandbox."
),
instruction="""\
You are a data analysis assistant. You work inside an isolated Daytona remote
sandbox that has internet access, where you can safely download data and run
Python, so you never touch the user's machine.

To analyze a dataset:
1. Download it from the internet into the working directory, e.g. with
`curl -O <url>` or `wget <url>`.
2. Install whatever you need on demand, e.g. `pip install pandas`.
3. Write a short Python script that loads the data and computes the answer.
4. Run the script and report the result, showing the numbers you found.

Prefer writing a script and executing it over guessing. If a command fails,
read the error, fix the script, and try again.
""",
tools=[EnvironmentToolset(environment=DaytonaEnvironment())],
)
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ optional-dependencies.agent-identity = [
]
optional-dependencies.all = [
"anyio>=4.9,<5",
"daytona>=0.191",
"e2b>=2,<3",
"google-api-python-client>=2.157,<3",
"google-cloud-aiplatform[agent-engines]>=1.148.1,<2",
Expand Down Expand Up @@ -101,6 +102,9 @@ optional-dependencies.benchmark = [
optional-dependencies.community = [
"google-adk-community",
]
optional-dependencies.daytona = [
"daytona>=0.191", # For DaytonaEnvironment remote sandbox.
]
optional-dependencies.db = [
"sqlalchemy>=2,<3",
"sqlalchemy-spanner>=1.14",
Expand Down Expand Up @@ -199,6 +203,7 @@ optional-dependencies.test = [
"anyio>=4.9,<5",
"beautifulsoup4>=3.2.2",
"crewai[tools]; python_version>='3.11' and python_version<'3.12'", # For CrewaiTool tests; chromadb/pypika fail on 3.12+
"daytona>=0.191",
"docker>=7", # For ContainerCodeExecutor tests
"e2b>=2,<3",
"gepa>=0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/google/adk/auth/auth_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async def run_async(
agent = invocation_context.agent
if not hasattr(agent, 'canonical_tools'):
return
events = invocation_context.session.events
events = invocation_context._get_events(current_branch=True)
if not events:
return

Expand Down
8 changes: 4 additions & 4 deletions src/google/adk/cli/cli_tools_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -1806,8 +1806,8 @@ def cli_web(
"""Starts a FastAPI server with Web UI for agents.

AGENTS_DIR: The directory of agents (where each subdirectory is a single
agent containing `agent.py` or `root_agent.yaml` files) or a path pointing
directly to a single agent folder.
agent containing `agent.py`, `__init__.py`, or `root_agent.yaml`) or a path
pointing directly to a single agent folder.

Example:

Expand Down Expand Up @@ -1947,8 +1947,8 @@ def cli_api_server(
"""Starts a FastAPI server for agents.

AGENTS_DIR: The directory of agents (where each subdirectory is a single
agent containing `agent.py` or `root_agent.yaml` files) or a path pointing
directly to a single agent folder.
agent containing `agent.py`, `__init__.py`, or `root_agent.yaml`) or a path
pointing directly to a single agent folder.

Example:

Expand Down
2 changes: 2 additions & 0 deletions src/google/adk/cli/utils/agent_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ def _determine_agent_language(
return "python"
elif (base_path / "__init__.py").exists():
return "python"
elif (base_path.parent / f"{agent_name}.py").exists():
return "python"

raise ValueError(f"Could not determine agent type for '{agent_name}'.")

Expand Down
8 changes: 8 additions & 0 deletions src/google/adk/features/_feature_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class FeatureName(str, Enum):
COMPUTER_USE = "COMPUTER_USE"
DATA_AGENT_TOOL_CONFIG = "DATA_AGENT_TOOL_CONFIG"
DATA_AGENT_TOOLSET = "DATA_AGENT_TOOLSET"
DAYTONA_ENVIRONMENT = "DAYTONA_ENVIRONMENT"
E2B_ENVIRONMENT = "E2B_ENVIRONMENT"
ENVIRONMENT_SIMULATION = "ENVIRONMENT_SIMULATION"
GCS_ADMIN_TOOLSET = "GCS_ADMIN_TOOLSET"
GCS_TOOL_SETTINGS = "GCS_TOOL_SETTINGS"
Expand Down Expand Up @@ -128,6 +130,12 @@ class FeatureConfig:
FeatureName.DATA_AGENT_TOOLSET: FeatureConfig(
FeatureStage.EXPERIMENTAL, default_on=True
),
FeatureName.DAYTONA_ENVIRONMENT: FeatureConfig(
FeatureStage.EXPERIMENTAL, default_on=True
),
FeatureName.E2B_ENVIRONMENT: FeatureConfig(
FeatureStage.EXPERIMENTAL, default_on=True
),
FeatureName.ENVIRONMENT_SIMULATION: FeatureConfig(
FeatureStage.EXPERIMENTAL, default_on=True
),
Expand Down
38 changes: 38 additions & 0 deletions src/google/adk/integrations/daytona/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Daytona sandbox integration.

This module provides a BaseEnvironment implementation backed by a Daytona
remote sandbox, offering a persistent remote workspace for file CRUD and
shell execution.

Requires the ``daytona`` extra: ``pip install google-adk[daytona]``.

Example:
```python
from google.adk.integrations.daytona import DaytonaEnvironment

env = DaytonaEnvironment()
await env.initialize()
result = await env.execute("pip install requests")
await env.close()
```
"""

from ._daytona_environment import DaytonaEnvironment

__all__ = [
"DaytonaEnvironment",
]
Loading
Loading