Skip to content

Commit 00ebaa2

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: GenAI SDK client - Add sandbox code execution SDK support
PiperOrigin-RevId: 797860270
1 parent 3bb8100 commit 00ebaa2

File tree

4 files changed

+1898
-3
lines changed

4 files changed

+1898
-3
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring
16+
17+
from tests.unit.vertexai.genai.replays import pytest_helper
18+
from vertexai._genai import types
19+
20+
21+
def test_create_sandbox(client):
22+
agent_engine = client.agent_engines.create()
23+
assert isinstance(agent_engine, types.AgentEngine)
24+
assert isinstance(agent_engine.api_resource, types.ReasoningEngine)
25+
26+
operation = client.agent_engines.sandboxes.create(
27+
name=agent_engine.api_resource.name,
28+
spec={
29+
"code_execution_environment": {
30+
"machineConfig": "MACHINE_CONFIG_VCPU4_RAM4GIB"
31+
}
32+
},
33+
config=types.CreateAgentEngineSandboxConfig(display_name="test_sandbox"),
34+
)
35+
assert isinstance(operation, types.AgentEngineSandboxOperation)
36+
assert operation.response.display_name == "test_sandbox"
37+
assert operation.response.spec == {
38+
"code_execution_environment": {"machineConfig": "MACHINE_CONFIG_VCPU4_RAM4GIB"}
39+
}
40+
assert operation.response.name.startswith(agent_engine.api_resource.name)
41+
42+
43+
pytestmark = pytest_helper.setup(
44+
file=__file__,
45+
globals_for_file=globals(),
46+
test_method="agent_engines.create_sandbox",
47+
)

vertexai/_genai/agent_engines.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ def _update(
907907
return return_value
908908

909909
_memories = None
910+
_sandboxes = None
910911
_sessions = None
911912

912913
@property
@@ -928,6 +929,25 @@ def memories(self):
928929
) from e
929930
return self._memories.Memories(self._api_client)
930931

932+
@property
933+
@_common.experimental_warning(
934+
"The Vertex SDK GenAI agent_engines.sandboxes module is experimental, "
935+
"and may change in future versions."
936+
)
937+
def sandboxes(self):
938+
if self._sandboxes is None:
939+
try:
940+
# We need to lazy load the sandboxes module to handle the
941+
# possibility of ImportError when dependencies are not installed.
942+
self._sandboxes = importlib.import_module(".sandboxes", __package__)
943+
except ImportError as e:
944+
raise ImportError(
945+
"The agent_engines.sandboxes module requires additional"
946+
" packages. Please install them using pip install"
947+
" google-cloud-aiplatform[agent_engines]"
948+
) from e
949+
return self._sandboxes.Sandboxes(self._api_client)
950+
931951
@property
932952
@_common.experimental_warning(
933953
"The Vertex SDK GenAI agent_engines.sessions module is experimental, "

0 commit comments

Comments
 (0)