snowflake-sandbox-python 0.2.2a8__tar.gz → 0.2.2a9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/PKG-INFO +1 -1
  2. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/pyproject.toml +1 -1
  3. snowflake_sandbox_python-0.2.2a9/src/snowflake/sandbox/_bundle_config.py +312 -0
  4. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_version.py +1 -1
  5. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/bundles.py +1 -7
  6. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/client.py +49 -17
  7. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/sync_client.py +49 -17
  8. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake_sandbox_python.egg-info/PKG-INFO +1 -1
  9. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake_sandbox_python.egg-info/SOURCES.txt +1 -0
  10. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/LICENSE +0 -0
  11. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/README.md +0 -0
  12. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/setup.cfg +0 -0
  13. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/setup.py +0 -0
  14. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/cli_sandbox/__init__.py +0 -0
  15. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/cli_sandbox/_adapter.py +0 -0
  16. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/cli_sandbox/_common.py +0 -0
  17. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/cli_sandbox/_egress_flags.py +0 -0
  18. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/cli_sandbox/_get_command.py +0 -0
  19. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/cli_sandbox/_git_repo_flags.py +0 -0
  20. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/cli_sandbox/_lifecycle_command.py +0 -0
  21. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/cli_sandbox/_remote_command.py +0 -0
  22. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/cli_sandbox/_run_command.py +0 -0
  23. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/cli_sandbox/_shell_command.py +0 -0
  24. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/cli_sandbox/_upload_plan.py +0 -0
  25. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/cli_sandbox/commands.py +0 -0
  26. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/cli_sandbox/plugin_spec.py +0 -0
  27. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/cli_sandbox/py.typed +0 -0
  28. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/__init__.py +0 -0
  29. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/__main__.py +0 -0
  30. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_ansi.py +0 -0
  31. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_args.py +0 -0
  32. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_assemble.py +0 -0
  33. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_build_context.py +0 -0
  34. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_build_context_fs.py +0 -0
  35. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_bundle.py +0 -0
  36. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_code_delivery.py +0 -0
  37. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_connection_resolve.py +0 -0
  38. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_deploy_spec.py +0 -0
  39. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_diagnostics.py +0 -0
  40. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_env.py +0 -0
  41. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_files_mixin.py +0 -0
  42. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_fs_ops.py +0 -0
  43. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_globs.py +0 -0
  44. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_hosts.py +0 -0
  45. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_mcp_discovery.py +0 -0
  46. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_mcp_status.py +0 -0
  47. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_preview.py +0 -0
  48. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_proto/__init__.py +0 -0
  49. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_proto/sandbox_pb2.py +0 -0
  50. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_proto/sandbox_pb2.pyi +0 -0
  51. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_retry.py +0 -0
  52. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_runtime/__init__.py +0 -0
  53. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_runtime/_fs_helper.py +0 -0
  54. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_runtime/_job_runner.py +0 -0
  55. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_runtime/_protocol.py +0 -0
  56. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_runtime/_shims.py +0 -0
  57. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_sandbox_state.py +0 -0
  58. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_session.py +0 -0
  59. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_session_registry.py +0 -0
  60. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_sse.py +0 -0
  61. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_ssh.py +0 -0
  62. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_ssh_trace.py +0 -0
  63. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_stage.py +0 -0
  64. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_sync_files_mixin.py +0 -0
  65. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_sync_fs_ops.py +0 -0
  66. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_sync_transport.py +0 -0
  67. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_sync_watch.py +0 -0
  68. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_transport.py +0 -0
  69. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_transport_errors.py +0 -0
  70. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_tunnel.py +0 -0
  71. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_upload_plan.py +0 -0
  72. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_watch.py +0 -0
  73. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/_wire.py +0 -0
  74. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/app.py +0 -0
  75. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/config.py +0 -0
  76. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/connect.py +0 -0
  77. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/deploy.py +0 -0
  78. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/egress.py +0 -0
  79. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/endpoint.py +0 -0
  80. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/exceptions.py +0 -0
  81. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/exec_stream.py +0 -0
  82. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/failure.py +0 -0
  83. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/files.py +0 -0
  84. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/function.py +0 -0
  85. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/git_repo.py +0 -0
  86. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/image.py +0 -0
  87. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/jobs.py +0 -0
  88. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/lifecycle.py +0 -0
  89. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/log_stream.py +0 -0
  90. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/mcp.py +0 -0
  91. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/mount.py +0 -0
  92. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/py.typed +0 -0
  93. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/secret.py +0 -0
  94. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/session_app.py +0 -0
  95. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/shell.py +0 -0
  96. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/snowflake_connection.py +0 -0
  97. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/sync_exec_stream.py +0 -0
  98. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/sync_files.py +0 -0
  99. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/sync_log_stream.py +0 -0
  100. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/sync_shell.py +0 -0
  101. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/types.py +0 -0
  102. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake/sandbox/warm_session.py +0 -0
  103. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake_sandbox_python.egg-info/dependency_links.txt +0 -0
  104. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake_sandbox_python.egg-info/entry_points.txt +0 -0
  105. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake_sandbox_python.egg-info/requires.txt +0 -0
  106. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/src/snowflake_sandbox_python.egg-info/top_level.txt +0 -0
  107. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/tests/test_docs_references.py +0 -0
  108. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/tests/test_gate_tristate.py +0 -0
  109. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/tests/test_imports.py +0 -0
  110. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/tests/test_smoke_offline.py +0 -0
  111. {snowflake_sandbox_python-0.2.2a8 → snowflake_sandbox_python-0.2.2a9}/tests/test_tutorial_sources.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: snowflake-sandbox-python
3
- Version: 0.2.2a8
3
+ Version: 0.2.2a9
4
4
  Summary: Snowflake sandboxes — Python SDK and CLI.
5
5
  Author: Snowflake, Inc.
6
6
  License:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "snowflake-sandbox-python"
7
- version = "0.2.2a8"
7
+ version = "0.2.2a9"
8
8
  description = "Snowflake sandboxes — Python SDK and CLI."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -0,0 +1,312 @@
1
+ """Compile authored sandbox settings without creating a sandbox or resolving credentials."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import math
7
+ import re
8
+ from collections.abc import Mapping
9
+ from typing import Any
10
+
11
+ from snowflake.sandbox._args import _validate_tags
12
+ from snowflake.sandbox._env import validate_env_mapping
13
+ from snowflake.sandbox._wire import _idle_suspend_minutes
14
+ from snowflake.sandbox.bundles import _publication_request
15
+ from snowflake.sandbox.egress import Egress, _compile_create_secrets, _validate_outbound_wif_hosts
16
+ from snowflake.sandbox.exceptions import (
17
+ SandboxError,
18
+ SandboxNotImplementedError,
19
+ SandboxValidationError,
20
+ )
21
+ from snowflake.sandbox.git_repo import GitRepo, validate_git_repos
22
+ from snowflake.sandbox.image import Image
23
+ from snowflake.sandbox.mcp import validate_mcp_servers
24
+ from snowflake.sandbox.mount import StageMount, validate_stage_mounts
25
+ from snowflake.sandbox.secret import Secret
26
+ from snowflake.sandbox.snowflake_connection import _coerce_snowflake_connection
27
+
28
+ _FIELDS = {
29
+ "image",
30
+ "memory",
31
+ "cpu",
32
+ "command",
33
+ "env",
34
+ "egress",
35
+ "secrets",
36
+ "stage_mounts",
37
+ "git_repos",
38
+ "mcp_servers",
39
+ "tags",
40
+ "snowflake_connection",
41
+ "mount_snowflake_config",
42
+ "omit_snowflake_token",
43
+ "idle_suspend",
44
+ }
45
+ _CPUS = {"1g": 1, "4g": 2, "8g": 3, "16g": 4, "32g": 6, "64g": 8}
46
+
47
+
48
+ def _config_publication_request(
49
+ db: str, schema: str, name: str, config: Mapping[str, Any]
50
+ ) -> dict[str, object]:
51
+ destination = _publication_request(db, schema, name)
52
+ destination.pop("include_filesystem")
53
+ if not isinstance(config, Mapping) or any(key not in _FIELDS for key in config):
54
+ raise SandboxValidationError("config must contain supported Sandbox.create settings only")
55
+ compute = _compute_options(config)
56
+ environment = validate_env_mapping(config.get("env"), context="bundle config")
57
+ egress, bindings = _compile_create_secrets(
58
+ _validated_egress(config.get("egress")), _validated_secrets(config.get("secrets"))
59
+ )
60
+ egress = egress or {}
61
+ properties = _base_properties(config, egress)
62
+ secret_names = _secret_fields(properties, egress, bindings)
63
+ specification: dict[str, Any] = {
64
+ "type": "custom",
65
+ "compute_type": "sandbox",
66
+ "compute_options": compute,
67
+ "properties": properties,
68
+ **_mounted_resources(config, properties),
69
+ }
70
+ if environment:
71
+ specification["env_vars"] = [{key: environment[key]} for key in sorted(environment)]
72
+ if secret_names:
73
+ specification["secrets"] = secret_names
74
+ integrations = egress.get("external_access_integrations") or []
75
+ assert isinstance(integrations, list)
76
+ for integration in integrations:
77
+ _reference(integration, 1)
78
+ if egress.get("external_access_integrations"):
79
+ specification["external_access_integrations"] = egress["external_access_integrations"]
80
+ try:
81
+ manifest = json.dumps(
82
+ {"bundle": specification},
83
+ ensure_ascii=False,
84
+ allow_nan=False,
85
+ sort_keys=True,
86
+ separators=(",", ":"),
87
+ )
88
+ if len(manifest.encode("utf-8")) > 1 << 20:
89
+ raise SandboxValidationError("Bundle definition exceeds the 1 MiB manifest limit.")
90
+ except (ValueError, TypeError, UnicodeError):
91
+ raise SandboxValidationError(
92
+ "Bundle configuration must contain valid JSON values."
93
+ ) from None
94
+ return {**destination, "manifest": manifest}
95
+
96
+
97
+ def _validated_egress(value: object) -> Mapping[str, Any] | None:
98
+ # The create compiler tolerates raw wire input and drops malformed nested secrets.
99
+ # Validate before compiling so publication cannot silently lose authored settings.
100
+ if value is None:
101
+ return None
102
+ if isinstance(value, Egress):
103
+ value = value.to_wire()
104
+ if not isinstance(value, Mapping):
105
+ raise SandboxValidationError("egress must be an Egress or mapping")
106
+ body = dict(value)
107
+ levels = ("allow_internet", "allow_public_package_registries", "allow_default_egress")
108
+ if any(
109
+ key not in (*levels, "external_access_integrations", "outbound_wif_hosts", "secrets")
110
+ for key in body
111
+ ):
112
+ raise SandboxValidationError("Unsupported egress setting in bundle config.")
113
+ for key in levels:
114
+ if key in body and not isinstance(body[key], bool):
115
+ raise SandboxValidationError("egress access settings must be booleans")
116
+ for key in ("external_access_integrations", "outbound_wif_hosts"):
117
+ if key in body:
118
+ values = body[key]
119
+ if not isinstance(values, (list, tuple)) or any(
120
+ not isinstance(item, str) for item in values
121
+ ):
122
+ raise SandboxValidationError(
123
+ "egress host and integration settings must be string lists"
124
+ )
125
+ body[key] = list(values)
126
+ if "outbound_wif_hosts" in body:
127
+ try:
128
+ _validate_outbound_wif_hosts(body["outbound_wif_hosts"])
129
+ except SandboxError:
130
+ raise SandboxValidationError("Invalid outbound WIF hosts in bundle config.") from None
131
+ if "secrets" in body:
132
+ body["secrets"] = _validated_secrets(body["secrets"], proxy=True)
133
+ return body
134
+
135
+
136
+ def _validated_secrets(value: object, *, proxy: bool = False) -> list[dict[str, Any]]:
137
+ if value is None:
138
+ return []
139
+ if not isinstance(value, (list, tuple)):
140
+ raise SandboxValidationError("secrets must be a list of secret references")
141
+ fields = (
142
+ {"fqn", "allowed_host", "env_var"} if proxy else {"fqn", "allowed_host", "env_var", "key"}
143
+ )
144
+ entries = []
145
+ for entry in value:
146
+ if isinstance(entry, Secret) and not proxy:
147
+ entry = entry.to_wire()
148
+ if (
149
+ not isinstance(entry, Mapping)
150
+ or not isinstance(entry.get("fqn"), str)
151
+ or any(
152
+ key not in fields or (val is not None and not isinstance(val, str))
153
+ for key, val in entry.items()
154
+ )
155
+ ):
156
+ raise SandboxValidationError("Unsupported secret setting in bundle config.")
157
+ entries.append({key: val for key, val in entry.items() if val is not None})
158
+ return entries
159
+
160
+
161
+ def _compute_options(config: Mapping[str, Any]) -> dict[str, Any]:
162
+ image = config.get("image")
163
+ if isinstance(image, Image):
164
+ if image.needs_preparation:
165
+ raise SandboxNotImplementedError("Build the image before publishing its configuration.")
166
+ image = image.name
167
+ if (
168
+ not isinstance(image, str)
169
+ or re.fullmatch(
170
+ r"/[A-Za-z0-9_#.-]+(?:/[A-Za-z0-9_#.-]+){2,}:[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}", image
171
+ )
172
+ is None
173
+ ):
174
+ raise SandboxValidationError("Publishing requires an explicit tagged image reference.")
175
+ memory = config.get("memory", "4g")
176
+ if memory is None or memory == "":
177
+ memory = "4g"
178
+ if not isinstance(memory, str) or memory not in _CPUS:
179
+ raise SandboxValidationError("Publishing requires a supported memory tier.")
180
+ cpu = config.get("cpu")
181
+ if cpu is None:
182
+ cpu = _CPUS[memory]
183
+ if isinstance(cpu, bool) or not isinstance(cpu, (int, float)) or cpu <= 0:
184
+ raise SandboxValidationError("cpu must be finite and greater than zero")
185
+ try:
186
+ finite = math.isfinite(cpu)
187
+ except OverflowError:
188
+ finite = False
189
+ if not finite:
190
+ raise SandboxValidationError("cpu must be finite and greater than zero")
191
+ return {"runtime_version": image, "cpu": cpu, "memory": memory[:-1] + "Gi"}
192
+
193
+
194
+ def _base_properties(config: Mapping[str, Any], egress: Mapping[str, Any]) -> dict[str, Any]:
195
+ properties: dict[str, Any] = {
196
+ "egress": {"allow_public_package_registries": egress.get("allow_internet", True)},
197
+ "snowflake_connection": {"render_connection_file": True},
198
+ "omit_snowflake_token": False,
199
+ }
200
+ command = config.get("command")
201
+ if command is not None:
202
+ if (
203
+ not isinstance(command, (list, tuple))
204
+ or not command
205
+ or not command[0]
206
+ or any(not isinstance(arg, str) or "\0" in arg for arg in command)
207
+ ):
208
+ raise SandboxValidationError("command must be a nonempty string argv")
209
+ properties["command"] = list(command)
210
+ for key in ("mount_snowflake_config", "omit_snowflake_token"):
211
+ if key in config and not isinstance(config[key], bool):
212
+ raise SandboxValidationError(key + " must be a boolean")
213
+ connection = _coerce_snowflake_connection(config.get("snowflake_connection"))
214
+ connection_body = connection._to_body() if connection is not None else {}
215
+ properties["snowflake_connection"]["render_connection_file"] = connection_body.get(
216
+ "render_connection_file", config.get("mount_snowflake_config", True)
217
+ )
218
+ properties["omit_snowflake_token"] = config.get("omit_snowflake_token", False)
219
+ idle = config.get("idle_suspend")
220
+ if idle is not None:
221
+ minutes = _idle_suspend_minutes(idle)
222
+ if minutes is None or not 1 <= minutes <= 1440:
223
+ raise SandboxValidationError("idle_suspend must be between 1 and 1440 whole minutes")
224
+ properties["idle_suspend_minutes"] = minutes
225
+ tags = _validate_tags(config.get("tags"), context="bundle config")
226
+ if tags:
227
+ properties["tags"] = tags
228
+ for key in ("outbound_wif_hosts", "secrets"):
229
+ if egress.get(key):
230
+ properties["egress"][key] = egress[key]
231
+ return properties
232
+
233
+
234
+ def _secret_fields(
235
+ properties: dict[str, Any],
236
+ egress: Mapping[str, Any],
237
+ bindings: list[dict[str, object]] | None,
238
+ ) -> list[str]:
239
+ proxy_secrets = egress.get("secrets") or []
240
+ assert isinstance(proxy_secrets, list)
241
+ for entry in proxy_secrets:
242
+ _reference(entry["fqn"], 3)
243
+ if proxy_secrets:
244
+ properties["egress"]["secrets"] = [
245
+ {
246
+ key: value
247
+ for key, value in entry.items()
248
+ if value is not None and key in ("fqn", "allowed_host", "env_var")
249
+ }
250
+ for entry in proxy_secrets
251
+ ]
252
+ secret_names = {secret["fqn"] for secret in proxy_secrets}
253
+ if bindings:
254
+ properties["secret_bindings"] = []
255
+ for entry in bindings:
256
+ _reference(entry["fqn"], 3)
257
+ secret_names.add(entry["fqn"])
258
+ binding = {
259
+ "fqn": entry["fqn"],
260
+ "key": entry.get("key", "secret_string"),
261
+ "env_var": entry["env_var"],
262
+ }
263
+ host = entry.get("allowed_host")
264
+ if isinstance(host, str) and host:
265
+ binding["allowed_hosts"] = [part.strip() for part in host.split(",")]
266
+ properties["secret_bindings"].append(binding)
267
+ return sorted(secret_names)
268
+
269
+
270
+ def _mounted_resources(config: Mapping[str, Any], properties: dict[str, Any]) -> dict[str, Any]:
271
+ mounts = list(config.get("stage_mounts") or ())
272
+ repos = list(config.get("git_repos") or ())
273
+ if any(not isinstance(mount, StageMount) for mount in mounts) or any(
274
+ not isinstance(repo, GitRepo) for repo in repos
275
+ ):
276
+ raise SandboxValidationError("Use StageMount and GitRepo values in bundle config.")
277
+ validate_stage_mounts(mounts)
278
+ validate_git_repos(repos, mounts)
279
+ for repo in repos:
280
+ _reference(repo.integration, 1)
281
+ if repos:
282
+ properties["git_repos"] = [repo.to_api_dict() for repo in repos]
283
+ servers = validate_mcp_servers(list(config.get("mcp_servers") or ()))
284
+ for server in servers:
285
+ _reference(server["fqn"], 3)
286
+ if servers:
287
+ properties["mcp_servers"] = servers
288
+ fields: dict[str, Any] = {}
289
+ if mounts:
290
+ fields["stage_mounts"] = {}
291
+ for index, mount in enumerate(mounts, 1):
292
+ entry = mount.to_api_dict()
293
+ if not entry.get("mount_path"):
294
+ raise SandboxValidationError("Publishing a stage mount requires mount_path.")
295
+ stage = str(entry.pop("stage_name")).removeprefix("@")
296
+ _reference(stage, 3)
297
+ value = {
298
+ "stage_url": "@" + stage,
299
+ "readonly": False,
300
+ **entry,
301
+ }
302
+ fields["stage_mounts"][f"mount_{index}"] = value
303
+ return fields
304
+
305
+
306
+ def _reference(value: object, parts: int) -> None:
307
+ identifier = r'(?:[A-Za-z_][A-Za-z0-9_$]*|"(?:[^"]|"")+")'
308
+ pattern = rf"\s*{identifier}(?:\s*\.\s*{identifier}){{{parts - 1}}}\s*"
309
+ if not isinstance(value, str) or "\0" in value or re.fullmatch(pattern, value) is None:
310
+ raise SandboxValidationError(
311
+ "Use fully qualified dependency references and account-level integration names."
312
+ )
@@ -29,7 +29,7 @@ __all__ = ["__version__"]
29
29
  _DIST_NAME = "snowflake-sandbox-python"
30
30
 
31
31
  # Keep in sync with [project].version in pyproject.toml.
32
- _FALLBACK_VERSION = "0.2.2a8"
32
+ _FALLBACK_VERSION = "0.2.2a9"
33
33
 
34
34
  try:
35
35
  __version__: str = _pkg_version(_DIST_NAME)
@@ -119,14 +119,8 @@ def _bundle_startup_timeout(payload: object) -> float:
119
119
  return float(payload)
120
120
 
121
121
 
122
- def _publication_request(
123
- db: str, schema: str, name: str, include_filesystem: bool
124
- ) -> dict[str, object]:
122
+ def _publication_request(db: str, schema: str, name: str) -> dict[str, object]:
125
123
  reference = BundleReference(db=db, schema=schema, name=name)
126
- if not isinstance(include_filesystem, bool):
127
- raise SandboxValidationError("include_filesystem must be a boolean")
128
- if include_filesystem:
129
- raise SandboxNotImplementedError("Filesystem sharing is not supported yet.")
130
124
  return {
131
125
  "db": reference.db,
132
126
  "schema": reference.schema,
@@ -28,6 +28,7 @@ from snowflake.sandbox._args import (
28
28
  _validate_tags,
29
29
  _wrap_detached,
30
30
  )
31
+ from snowflake.sandbox._bundle_config import _config_publication_request
31
32
  from snowflake.sandbox._env import validate_env_mapping
32
33
  from snowflake.sandbox._files_mixin import _FilesMixin
33
34
  from snowflake.sandbox._preview import app_host_suffix, preview_url, validate_preview_port
@@ -404,30 +405,61 @@ class AsyncSandbox(_FilesMixin, _SandboxState):
404
405
  raise SandboxError("sandbox has no id yet -- call create() (or use async with)")
405
406
  return self._id
406
407
 
407
- async def publish(
408
- self, *, db: str, schema: str, name: str, include_filesystem: bool = False
408
+ @classmethod
409
+ async def publish_bundle(
410
+ cls,
411
+ *,
412
+ db: str,
413
+ schema: str,
414
+ name: str,
415
+ config: Mapping[str, Any] | None = None,
416
+ sandbox: Self | None = None,
417
+ connection: ConnectionLike | None = None,
409
418
  ) -> BundlePublication:
410
- """Save this sandbox's retained definition as a named Code Bundle version.
419
+ """Publish a named Code Bundle from configuration or a sandbox snapshot.
411
420
 
412
- Uses the server's saved creation settings, including when reconnected.
413
- Changes to the running filesystem are excluded. The caller needs permission
414
- to create or update the destination bundle. Filesystem sharing is not yet
415
- supported. Publication never creates or resumes the source sandbox.
416
- M1 requires a tagged image and fully qualified secret, stage and MCP
417
- references. User-relative stages and unqualified references are rejected
418
- by the server; normal sandbox creation is unchanged.
421
+ Note:
422
+ Provide exactly one of ``config`` or ``sandbox``. Configuration accepts
423
+ supported ``Sandbox.create`` settings and requires an explicit tagged
424
+ image. It saves settings and dependency references without starting a
425
+ sandbox. Local uploads and live processes are excluded. Stage mounts
426
+ require explicit mount paths and fully qualified stage names.
427
+
428
+ A sandbox source requests a filesystem snapshot using its own connection.
429
+ Snapshot publication requires platform support; unsupported platforms
430
+ raise ``SandboxNotImplementedError`` without saving configuration instead.
431
+ Do not pass ``connection`` with a sandbox source.
432
+
433
+ Publication checks destination and dependency permissions on every call.
434
+ Reusable code must live in the referenced image, stage, or repository.
419
435
 
420
436
  Example:
421
- publication = await sb.publish(db="TOOLS", schema="SANDBOX_LIBRARY", name="ANALYSIS")
422
- print(publication.status)
437
+ saved = await AsyncSandbox.publish_bundle(
438
+ db="TOOLS", schema="SANDBOX_LIBRARY", name="ANALYSIS",
439
+ config={"image": "/TOOLS.PUBLIC.IMAGES/analysis:v1", "memory": "1g"},
440
+ connection="my-connection",
441
+ )
442
+ print(saved.status)
423
443
  """
424
- source_id = self.id
425
- body = _publication_request(db, schema, name, include_filesystem)
444
+ if (config is None) == (sandbox is None):
445
+ raise SandboxValidationError("Provide exactly one of config or sandbox.")
446
+ if sandbox is not None:
447
+ if not isinstance(sandbox, cls) or connection is not None:
448
+ raise SandboxValidationError(
449
+ "A sandbox source must use its own client and connection."
450
+ )
451
+ body = _publication_request(db, schema, name)
452
+ body["include_filesystem"] = True
453
+ path = f"containers/{sandbox.id}/publish"
454
+ transport = sandbox._transport
455
+ else:
456
+ assert config is not None
457
+ body = _config_publication_request(db, schema, name, config)
458
+ path = "containers/bundles/publish"
459
+ transport = await _entry_transport(connection, None)
426
460
  failure: SandboxError | None = None
427
461
  try:
428
- response = await self._transport.request(
429
- "POST", f"containers/{source_id}/publish", json_body=body, retry_not_found=False
430
- )
462
+ response = await transport.request("POST", path, json_body=body, retry_not_found=False)
431
463
  except SandboxError as exc:
432
464
  failure = _public_bundle_error(exc, "publication")
433
465
  if failure is not None:
@@ -27,6 +27,7 @@ from snowflake.sandbox._args import (
27
27
  _validate_tags,
28
28
  _wrap_detached,
29
29
  )
30
+ from snowflake.sandbox._bundle_config import _config_publication_request
30
31
  from snowflake.sandbox._env import validate_env_mapping
31
32
  from snowflake.sandbox._preview import app_host_suffix, preview_url, validate_preview_port
32
33
  from snowflake.sandbox._retry import (
@@ -407,30 +408,61 @@ class Sandbox(_FilesMixin, _SandboxState):
407
408
  raise SandboxError("sandbox has no id yet -- call create() (or use with)")
408
409
  return self._id
409
410
 
410
- def publish(
411
- self, *, db: str, schema: str, name: str, include_filesystem: bool = False
411
+ @classmethod
412
+ def publish_bundle(
413
+ cls,
414
+ *,
415
+ db: str,
416
+ schema: str,
417
+ name: str,
418
+ config: Mapping[str, Any] | None = None,
419
+ sandbox: Self | None = None,
420
+ connection: ConnectionLike | None = None,
412
421
  ) -> BundlePublication:
413
- """Save this sandbox's retained definition as a named Code Bundle version.
422
+ """Publish a named Code Bundle from configuration or a sandbox snapshot.
414
423
 
415
- Uses the server's saved creation settings, including when reconnected.
416
- Changes to the running filesystem are excluded. The caller needs permission
417
- to create or update the destination bundle. Filesystem sharing is not yet
418
- supported. Publication never creates or resumes the source sandbox.
419
- M1 requires a tagged image and fully qualified secret, stage and MCP
420
- references. User-relative stages and unqualified references are rejected
421
- by the server; normal sandbox creation is unchanged.
424
+ Note:
425
+ Provide exactly one of ``config`` or ``sandbox``. Configuration accepts
426
+ supported ``Sandbox.create`` settings and requires an explicit tagged
427
+ image. It saves settings and dependency references without starting a
428
+ sandbox. Local uploads and live processes are excluded. Stage mounts
429
+ require explicit mount paths and fully qualified stage names.
430
+
431
+ A sandbox source requests a filesystem snapshot using its own connection.
432
+ Snapshot publication requires platform support; unsupported platforms
433
+ raise ``SandboxNotImplementedError`` without saving configuration instead.
434
+ Do not pass ``connection`` with a sandbox source.
435
+
436
+ Publication checks destination and dependency permissions on every call.
437
+ Reusable code must live in the referenced image, stage, or repository.
422
438
 
423
439
  Example:
424
- publication = sb.publish(db="TOOLS", schema="SANDBOX_LIBRARY", name="ANALYSIS")
425
- print(publication.status)
440
+ saved = Sandbox.publish_bundle(
441
+ db="TOOLS", schema="SANDBOX_LIBRARY", name="ANALYSIS",
442
+ config={"image": "/TOOLS.PUBLIC.IMAGES/analysis:v1", "memory": "1g"},
443
+ connection="my-connection",
444
+ )
445
+ print(saved.status)
426
446
  """
427
- source_id = self.id
428
- body = _publication_request(db, schema, name, include_filesystem)
447
+ if (config is None) == (sandbox is None):
448
+ raise SandboxValidationError("Provide exactly one of config or sandbox.")
449
+ if sandbox is not None:
450
+ if not isinstance(sandbox, cls) or connection is not None:
451
+ raise SandboxValidationError(
452
+ "A sandbox source must use its own client and connection."
453
+ )
454
+ body = _publication_request(db, schema, name)
455
+ body["include_filesystem"] = True
456
+ path = f"containers/{sandbox.id}/publish"
457
+ transport = sandbox._transport
458
+ else:
459
+ assert config is not None
460
+ body = _config_publication_request(db, schema, name, config)
461
+ path = "containers/bundles/publish"
462
+ transport = _entry_transport(connection, None)
429
463
  failure: SandboxError | None = None
430
464
  try:
431
- response = self._transport.request(
432
- "POST", f"containers/{source_id}/publish", json_body=body, retry_not_found=False
433
- )
465
+ response = transport.request("POST", path, json_body=body, retry_not_found=False)
434
466
  except SandboxError as exc:
435
467
  failure = _public_bundle_error(exc, "publication")
436
468
  if failure is not None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: snowflake-sandbox-python
3
- Version: 0.2.2a8
3
+ Version: 0.2.2a9
4
4
  Summary: Snowflake sandboxes — Python SDK and CLI.
5
5
  Author: Snowflake, Inc.
6
6
  License:
@@ -24,6 +24,7 @@ src/snowflake/sandbox/_assemble.py
24
24
  src/snowflake/sandbox/_build_context.py
25
25
  src/snowflake/sandbox/_build_context_fs.py
26
26
  src/snowflake/sandbox/_bundle.py
27
+ src/snowflake/sandbox/_bundle_config.py
27
28
  src/snowflake/sandbox/_code_delivery.py
28
29
  src/snowflake/sandbox/_connection_resolve.py
29
30
  src/snowflake/sandbox/_deploy_spec.py