Skip to content

Commit c3e2ce7

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Add support for templates sub-module for Sandboxes in Vertex AI GenAI SDK.
PiperOrigin-RevId: 904556301
1 parent 677b55e commit c3e2ce7

9 files changed

Lines changed: 1792 additions & 0 deletions
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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_sandbox_templates_byoc_create(client):
22+
# Override the base URL to point to the autopush environment
23+
client._api_client._http_options.base_url = (
24+
"https://us-central1-autopush-aiplatform.sandbox.googleapis.com"
25+
)
26+
container_image_uri = "us-central1-docker.pkg.dev/agent-sandbox-fishfood-1564/agent-sandbox/custom-jupiter-sandbox:latest"
27+
cpu_request = "1"
28+
memory_request = "500Mi"
29+
cpu_limit = "1"
30+
memory_limit = "500Mi"
31+
config = {
32+
"custom_container_environment": {
33+
"custom_container_spec": {
34+
"image_uri": container_image_uri
35+
},
36+
"resources": {
37+
"requests": {
38+
"cpu": cpu_request,
39+
"memory": memory_request,
40+
},
41+
"limits": {
42+
"cpu": cpu_limit,
43+
"memory": memory_limit,
44+
}
45+
},
46+
"ports": [
47+
{
48+
"port": 8080,
49+
"protocol": "TCP",
50+
}
51+
]
52+
},
53+
"egress_control_config": {
54+
"internet_access": True,
55+
},
56+
}
57+
sandbox_template_operation = client.agent_engines.sandboxes.templates.create(
58+
name=(
59+
"projects/254005681254/locations/us-central1/reasoningEngines/208148546254274560"
60+
),
61+
display_name="Test Sandbox Template 1",
62+
config=config,
63+
)
64+
assert isinstance(
65+
sandbox_template_operation,
66+
types.CreateSandboxEnvironmentTemplateOperation
67+
)
68+
69+
70+
pytestmark = pytest_helper.setup(
71+
file=__file__,
72+
globals_for_file=globals(),
73+
test_method="agent_engines.sandboxes.templates.create",
74+
)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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_sandbox_templates_default_create(client):
22+
# Override the base URL to point to the autopush environment
23+
client._api_client._http_options.base_url = (
24+
"https://us-central1-autopush-aiplatform.sandbox.googleapis.com"
25+
)
26+
config = {
27+
"default_container_environment": {
28+
"default_container_category": "DEFAULT_CONTAINER_CATEGORY_COMPUTER_USE",
29+
},
30+
"egress_control_config": {
31+
"internet_access": True,
32+
},
33+
}
34+
sandbox_template_operation = client.agent_engines.sandboxes.templates.create(
35+
name=(
36+
"projects/254005681254/locations/us-central1/reasoningEngines/208148546254274560"
37+
),
38+
display_name="Test Sandbox Template 1",
39+
config=config,
40+
)
41+
assert isinstance(
42+
sandbox_template_operation,
43+
types.CreateSandboxEnvironmentTemplateOperation
44+
)
45+
46+
47+
pytestmark = pytest_helper.setup(
48+
file=__file__,
49+
globals_for_file=globals(),
50+
test_method="agent_engines.sandboxes.templates.create",
51+
)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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_sandbox_templates_delete(client):
22+
# Override the base URL to point to the autopush environment
23+
client._api_client._http_options.base_url = (
24+
"https://us-central1-autopush-aiplatform.sandbox.googleapis.com"
25+
)
26+
sandbox_template_delete_operation = client.agent_engines.sandboxes.templates.delete(
27+
name=(
28+
"projects/254005681254/locations/us-central1/reasoningEngines/208148546254274560/sandboxEnvironmentTemplates/4632233691727265792"
29+
),
30+
)
31+
assert isinstance(
32+
sandbox_template_delete_operation,
33+
types.DeleteSandboxEnvironmentTemplateOperation
34+
)
35+
36+
37+
pytestmark = pytest_helper.setup(
38+
file=__file__,
39+
globals_for_file=globals(),
40+
test_method="agent_engines.sandboxes.templates.delete",
41+
)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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_sandbox_templates_get(client):
22+
# Override the base URL to point to the autopush environment
23+
client._api_client._http_options.base_url = (
24+
"https://us-central1-autopush-aiplatform.sandbox.googleapis.com"
25+
)
26+
sandbox_template_name = (
27+
"projects/254005681254/locations/us-central1/reasoningEngines/208148546254274560/sandboxEnvironmentTemplates/4632233691727265792"
28+
)
29+
30+
sandbox_template = client.agent_engines.sandboxes.templates.get(
31+
name=sandbox_template_name
32+
)
33+
assert isinstance(sandbox_template, types.SandboxEnvironmentTemplate)
34+
assert sandbox_template.name == sandbox_template_name
35+
36+
37+
pytestmark = pytest_helper.setup(
38+
file=__file__,
39+
globals_for_file=globals(),
40+
test_method="agent_engines.sandboxes.templates.get",
41+
)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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_sandbox_templates_list(client):
22+
# Override the base URL to point to the autopush environment
23+
client._api_client._http_options.base_url = (
24+
"https://us-central1-autopush-aiplatform.sandbox.googleapis.com"
25+
)
26+
sandbox_templates_list_operation = client.agent_engines.sandboxes.templates.list(
27+
name=(
28+
"projects/254005681254/locations/us-central1/reasoningEngines/208148546254274560"
29+
),
30+
)
31+
assert isinstance(
32+
sandbox_templates_list_operation.sandbox_environment_templates[0],
33+
types.SandboxEnvironmentTemplate,
34+
)
35+
assert isinstance(
36+
sandbox_templates_list_operation, types.ListSandboxEnvironmentTemplatesResponse
37+
)
38+
39+
40+
pytestmark = pytest_helper.setup(
41+
file=__file__,
42+
globals_for_file=globals(),
43+
test_method="agent_engines.sandboxes.templates.list",
44+
)

0 commit comments

Comments
 (0)