Skip to content

Commit 1389a4b

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Add support for snapshots for Sandboxes in Vertex AI GenAI SDK.
PiperOrigin-RevId: 897294488
1 parent 9ed3759 commit 1389a4b

8 files changed

Lines changed: 1344 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""Tests for Sandbox Snapshot create operation."""
2+
3+
# Copyright 2026 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring,bad-indentation
18+
19+
from tests.unit.vertexai.genai.replays import pytest_helper
20+
from vertexai._genai import types
21+
22+
23+
def test_create_sandbox_snapshot(client):
24+
# 1. Create an Agent Engine
25+
agent_engine = client.agent_engines.create()
26+
27+
# 2. Create a Sandbox
28+
sandbox_op = client.agent_engines.sandboxes.create(
29+
name=agent_engine.api_resource.name,
30+
poll_interval_seconds=1,
31+
spec={
32+
"code_execution_environment": {
33+
"machineConfig": "MACHINE_CONFIG_VCPU4_RAM4GIB"
34+
}
35+
},
36+
config=types.CreateAgentEngineSandboxConfig(
37+
display_name="test_sandbox", ttl="3600s"
38+
),
39+
)
40+
sandbox = sandbox_op.response
41+
42+
# 3. Create a Snapshot
43+
snapshot = client.agent_engines.sandboxes.snapshots.create(
44+
name=sandbox.name,
45+
sandbox_environment_snapshot={},
46+
)
47+
48+
assert isinstance(snapshot, types.SandboxEnvironmentSnapshot)
49+
50+
51+
pytestmark = pytest_helper.setup(
52+
file=__file__,
53+
globals_for_file=globals(),
54+
test_method="agent_engines.sandboxes.snapshots.create",
55+
)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""Tests for Sandbox Snapshot delete operation."""
2+
3+
# Copyright 2026 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring,bad-indentation
18+
19+
from tests.unit.vertexai.genai.replays import pytest_helper
20+
from vertexai._genai import types
21+
22+
23+
def test_delete_sandbox_snapshot(client):
24+
# 1. Create an Agent Engine
25+
agent_engine = client.agent_engines.create()
26+
27+
# 2. Create a Sandbox
28+
sandbox_op = client.agent_engines.sandboxes.create(
29+
name=agent_engine.api_resource.name,
30+
poll_interval_seconds=1,
31+
spec={
32+
"code_execution_environment": {
33+
"machineConfig": "MACHINE_CONFIG_VCPU4_RAM4GIB"
34+
}
35+
},
36+
config=types.CreateAgentEngineSandboxConfig(
37+
display_name="test_sandbox", ttl="3600s"
38+
),
39+
)
40+
sandbox = sandbox_op.response
41+
42+
# 3. Create a Snapshot
43+
snapshot = client.agent_engines.sandboxes.snapshots.create(
44+
name=sandbox.name,
45+
sandbox_environment_snapshot={},
46+
)
47+
48+
# 4. Delete the Snapshot
49+
result = client.agent_engines.sandboxes.snapshots.delete(
50+
name=snapshot.name,
51+
)
52+
53+
assert result is None
54+
55+
56+
pytestmark = pytest_helper.setup(
57+
file=__file__,
58+
globals_for_file=globals(),
59+
test_method="agent_engines.sandboxes.snapshots.delete",
60+
)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""Tests for Sandbox Snapshot get operation."""
2+
3+
# Copyright 2026 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring,bad-indentation
18+
19+
from tests.unit.vertexai.genai.replays import pytest_helper
20+
from vertexai._genai import types
21+
22+
23+
def test_get_sandbox_snapshot(client):
24+
# 1. Create an Agent Engine
25+
agent_engine = client.agent_engines.create()
26+
27+
# 2. Create a Sandbox
28+
sandbox_op = client.agent_engines.sandboxes.create(
29+
name=agent_engine.api_resource.name,
30+
poll_interval_seconds=1,
31+
spec={
32+
"code_execution_environment": {
33+
"machineConfig": "MACHINE_CONFIG_VCPU4_RAM4GIB"
34+
}
35+
},
36+
config=types.CreateAgentEngineSandboxConfig(
37+
display_name="test_sandbox", ttl="3600s"
38+
),
39+
)
40+
sandbox = sandbox_op.response
41+
42+
# 3. Create a Snapshot
43+
snapshot = client.agent_engines.sandboxes.snapshots.create(
44+
name=sandbox.name,
45+
sandbox_environment_snapshot={},
46+
)
47+
48+
# 4. Get the Snapshot
49+
fetched_snapshot = client.agent_engines.sandboxes.snapshots.get(
50+
name=snapshot.name,
51+
)
52+
53+
assert isinstance(fetched_snapshot, types.SandboxEnvironmentSnapshot)
54+
assert fetched_snapshot.name == snapshot.name
55+
56+
57+
pytestmark = pytest_helper.setup(
58+
file=__file__,
59+
globals_for_file=globals(),
60+
test_method="agent_engines.sandboxes.snapshots.get",
61+
)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""Tests for Sandbox Snapshot list operation."""
2+
3+
# Copyright 2026 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# pylint: disable=protected-access,bad-continuation,missing-function-docstring,bad-indentation
18+
19+
from tests.unit.vertexai.genai.replays import pytest_helper
20+
from vertexai._genai import types
21+
22+
23+
def test_list_sandbox_snapshots(client):
24+
# 1. Create an Agent Engine
25+
agent_engine = client.agent_engines.create()
26+
27+
# 2. Create a Sandbox
28+
sandbox_op = client.agent_engines.sandboxes.create(
29+
name=agent_engine.api_resource.name,
30+
poll_interval_seconds=1,
31+
spec={
32+
"code_execution_environment": {
33+
"machineConfig": "MACHINE_CONFIG_VCPU4_RAM4GIB"
34+
}
35+
},
36+
config=types.CreateAgentEngineSandboxConfig(
37+
display_name="test_sandbox", ttl="3600s"
38+
),
39+
)
40+
sandbox = sandbox_op.response
41+
42+
# 3. Create a Snapshot
43+
client.agent_engines.sandboxes.snapshots.create(
44+
name=sandbox.name,
45+
sandbox_environment_snapshot={},
46+
)
47+
48+
# 4. List Snapshots
49+
snapshots_pager = client.agent_engines.sandboxes.snapshots.list(
50+
name=sandbox.name,
51+
)
52+
53+
# Verify it returns a pager and we can iterate over it
54+
count = 0
55+
for snapshot in snapshots_pager:
56+
assert isinstance(snapshot, types.SandboxEnvironmentSnapshot)
57+
count += 1
58+
59+
assert count >= 1
60+
61+
62+
pytestmark = pytest_helper.setup(
63+
file=__file__,
64+
globals_for_file=globals(),
65+
test_method="agent_engines.sandboxes.snapshots.list",
66+
)

0 commit comments

Comments
 (0)