modal 1.6.5.dev7__tar.gz → 1.6.5.dev8__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.
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/PKG-INFO +1 -1
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/__init__.py +3 -0
- modal-1.6.5.dev7/modal/_outbound_policy.py → modal-1.6.5.dev8/modal/_experimental_outbound_policy.py +11 -28
- modal-1.6.5.dev7/modal/_outbound_policy.pyi → modal-1.6.5.dev8/modal/_experimental_outbound_policy.pyi +6 -7
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_image.py +5 -0
- modal-1.6.5.dev8/modal/_outbound_policy.py +443 -0
- modal-1.6.5.dev8/modal/_outbound_policy.pyi +471 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/client.pyi +2 -2
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/experimental/__init__.py +1 -1
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/image.pyi +1 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/sandbox/_common.py +124 -6
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/sandbox/_impl_persistent.py +8 -1
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/sandbox/_impl_v1.py +13 -3
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/sandbox/_impl_v2.py +14 -3
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/sandbox/_sandbox.py +76 -15
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/sandbox/_task_command_router_client.py +6 -5
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/sandbox/sandbox.pyi +108 -24
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/types.py +20 -1
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal.egg-info/PKG-INFO +1 -1
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal.egg-info/SOURCES.txt +2 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_proto/api_grpc.py +0 -16
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_proto/api_pb2.py +1114 -1124
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_proto/api_pb2.pyi +44 -39
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_proto/api_pb2_grpc.py +0 -33
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_proto/api_pb2_grpc.pyi +0 -10
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_proto/modal_api_grpc.py +0 -1
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_version/__init__.py +1 -1
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/LICENSE +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/README.md +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/__main__.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_audit_logs/__init__.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_audit_logs/_rpcs.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_audit_logs/count.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_audit_logs/list.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_billing.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_cluster.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_cluster.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_container_entrypoint.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_environments.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_function_variants.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_functions.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_grpc_client.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_ipython.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_load_context.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_location.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_logs.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_logs_manager.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_logs_manager.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_metrics.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_metrics.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_object.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_output/__init__.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_output/manager.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_output/pty.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_output/rich.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_output/status.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_partial_function.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_resolver.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_resources.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_runtime/__init__.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_runtime/asgi.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_runtime/container_io_manager.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_runtime/container_io_manager.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_runtime/execution_context.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_runtime/execution_context.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_runtime/gpu_memory_snapshot.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_runtime/task_lifecycle_manager.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_runtime/task_lifecycle_manager.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_runtime/telemetry.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_runtime/user_code_event_loop.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_runtime/user_code_imports.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_serialization.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_server.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_server.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_supports_logs.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_traceback.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_tunnel.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_tunnel.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_type_manager.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/__init__.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/app_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/async_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/auth_token_manager.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/blob_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/browser_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/bytes_io_segment_payload.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/curl_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/deprecation.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/display_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/docker_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/function_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/git_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/grpc_testing.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/grpc_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/hash_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/http_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/idle_countdown.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/jwt_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/logger.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/mount_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/name_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/oauth.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/package_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/pattern_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/proxy_support.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/rand_pb_testing.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/sandbox_fs_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/shell_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_utils/time_utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_vendor/__init__.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_vendor/a2wsgi_wsgi.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_vendor/cloudpickle.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_vendor/tblib.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_vendor/version.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_watcher.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/_workspace.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/app.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/app.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/billing.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/billing.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/builder/2023.12.312.txt +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/builder/2023.12.txt +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/builder/2024.04.txt +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/builder/2024.10.txt +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/builder/2025.06.txt +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/builder/2026.10.txt +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/builder/PREVIEW.txt +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/builder/README.md +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/builder/base-images.json +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/call_graph.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/__init__.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/_audit_logs.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/_download.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/_help.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/_logs.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/_stats.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/_suggest.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/_traceback.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/app.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/billing.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/changelog.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/config.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/container.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/curl.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/dashboard.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/dict.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/endpoint.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/entry_point.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/environment.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/function.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/image.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/import_refs.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/logo.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/network_file_system.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/profile.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/queues.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/run.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/secret.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/selector.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/server.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/shell.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/skills.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/token.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/utils.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/volume.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cli/workspace.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/client.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cloud_bucket_mount.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cloud_bucket_mount.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cls.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cls.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cluster.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/cluster.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/config.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/container_process.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/container_process.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/dict.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/dict.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/environments.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/environments.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/exception.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/experimental/_flash_container_entry.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/experimental/flash.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/experimental/flash.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/experimental/flash_server.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/experimental/flash_server.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/experimental/stream.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/experimental/stream.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/file_pattern_matcher.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/functions.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/functions.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/image.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/io_streams.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/io_streams.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/mount.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/mount.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/network_file_system.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/network_file_system.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/object.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/object.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/output.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/parallel_map.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/parallel_map.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/partial_function.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/partial_function.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/proxy.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/proxy.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/py.typed +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/queue.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/queue.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/retries.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/runner.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/runner.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/running_app.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/sandbox/__init__.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/sandbox/_filesystem.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/sandbox/_sidecar.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/sandbox/_snapshot.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/sandbox/sandbox.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/schedule.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/scheduler_placement.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/secret.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/secret.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/server.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/server.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/serving.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/serving.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/skills/modal/SKILL.md +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/stream_type.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/token_flow.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/token_flow.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/volume.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/volume.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/workspace.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal/workspace.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal.egg-info/dependency_links.txt +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal.egg-info/entry_points.txt +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal.egg-info/requires.txt +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal.egg-info/top_level.txt +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_docs/__init__.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_docs/gen_cli_docs.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_docs/gen_cli_docs_main.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_docs/gen_reference_docs.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_docs/gen_reference_docs_main.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_docs/mdmd/__init__.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_docs/mdmd/mdmd.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_docs/mdmd/signatures.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_docs/mdmd/types.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_docs/reference_intro.md +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_proto/__init__.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_proto/py.typed +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_proto/task_command_router_grpc.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_proto/task_command_router_pb2.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_proto/task_command_router_pb2.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_proto/task_command_router_pb2_grpc.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_proto/task_command_router_pb2_grpc.pyi +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/modal_version/__main__.py +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/pyproject.toml +0 -0
- {modal-1.6.5.dev7 → modal-1.6.5.dev8}/setup.cfg +0 -0
|
@@ -11,6 +11,7 @@ from modal_version import __version__
|
|
|
11
11
|
|
|
12
12
|
try:
|
|
13
13
|
from . import billing, experimental, types
|
|
14
|
+
from ._outbound_policy import OutboundPolicy, OutboundRoute
|
|
14
15
|
from ._runtime.execution_context import current_function_call_id, current_input_id, interact, is_local
|
|
15
16
|
from ._tunnel import Tunnel, forward
|
|
16
17
|
from .app import App
|
|
@@ -86,6 +87,8 @@ __all__ = [
|
|
|
86
87
|
"FunctionCall",
|
|
87
88
|
"Image",
|
|
88
89
|
"NetworkFileSystem",
|
|
90
|
+
"OutboundPolicy",
|
|
91
|
+
"OutboundRoute",
|
|
89
92
|
"Period",
|
|
90
93
|
"Probe",
|
|
91
94
|
"Proxy",
|
modal-1.6.5.dev7/modal/_outbound_policy.py → modal-1.6.5.dev8/modal/_experimental_outbound_policy.py
RENAMED
|
@@ -3,40 +3,22 @@
|
|
|
3
3
|
|
|
4
4
|
from __future__ import annotations
|
|
5
5
|
|
|
6
|
-
import re
|
|
7
6
|
from dataclasses import dataclass
|
|
8
7
|
from typing import Mapping, Sequence
|
|
9
8
|
|
|
10
9
|
from modal_proto import api_pb2
|
|
11
10
|
|
|
11
|
+
from ._outbound_policy import (
|
|
12
|
+
_header_value_has_invalid_chars,
|
|
13
|
+
_is_valid_domain,
|
|
14
|
+
_is_valid_header_name,
|
|
15
|
+
_template_references_key,
|
|
16
|
+
)
|
|
12
17
|
from ._utils.async_utils import synchronize_api
|
|
13
18
|
from .exception import InvalidError
|
|
14
19
|
from .secret import _Secret
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
r"^(\*\.)?([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\Z"
|
|
18
|
-
)
|
|
19
|
-
_HEADER_NAME_RE = re.compile(r"^[A-Za-z0-9!#$%&'*+.^_`|~-]+\Z")
|
|
20
|
-
|
|
21
|
-
_MAX_HEADER_REPLACEMENTS = 25
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def _header_value_has_invalid_chars(value: str) -> bool:
|
|
25
|
-
return any((ord(c) < 0x20 and c != "\t") or ord(c) == 0x7F for c in value)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def _template_references_key(template: str) -> bool:
|
|
29
|
-
"""Whether a header value template references a `$KEY`."""
|
|
30
|
-
i = template.find("$")
|
|
31
|
-
while i != -1 and i + 1 < len(template):
|
|
32
|
-
c = template[i + 1]
|
|
33
|
-
if c == "$":
|
|
34
|
-
i = template.find("$", i + 2)
|
|
35
|
-
continue
|
|
36
|
-
if c.isascii() and (c.isalpha() or c == "_"):
|
|
37
|
-
return True
|
|
38
|
-
i = template.find("$", i + 1)
|
|
39
|
-
return False
|
|
21
|
+
_MAX_HEADER_REPLACEMENTS: int = 25
|
|
40
22
|
|
|
41
23
|
|
|
42
24
|
@dataclass(frozen=True)
|
|
@@ -50,7 +32,8 @@ class _OutboundPolicy:
|
|
|
50
32
|
"""Immutable configuration for replacing headers in outbound HTTPS requests
|
|
51
33
|
from a Sandbox.
|
|
52
34
|
|
|
53
|
-
|
|
35
|
+
Deprecated, and removed in modal 1.7.0: use `modal.OutboundPolicy` with
|
|
36
|
+
`modal.OutboundRoute.https(..., header_replacements=...)` routes instead.
|
|
54
37
|
|
|
55
38
|
Header values support templating with keys in a replacement's secret: a
|
|
56
39
|
`$`-prefixed key name in the secret is replaced with the secret value.
|
|
@@ -115,12 +98,12 @@ class _OutboundPolicy:
|
|
|
115
98
|
"""Check all replacements, raising `InvalidError` on the first violation found."""
|
|
116
99
|
total = 0
|
|
117
100
|
for replacement in self._replacements:
|
|
118
|
-
if
|
|
101
|
+
if not _is_valid_domain(replacement.domain):
|
|
119
102
|
raise InvalidError(f"Invalid domain: {replacement.domain!r}")
|
|
120
103
|
if not replacement.headers:
|
|
121
104
|
raise InvalidError("`headers` must contain at least one header")
|
|
122
105
|
for name, value in replacement.headers.items():
|
|
123
|
-
if not
|
|
106
|
+
if not _is_valid_header_name(name):
|
|
124
107
|
raise InvalidError(f"Invalid header name: {name!r}")
|
|
125
108
|
if _header_value_has_invalid_chars(value):
|
|
126
109
|
raise InvalidError(f"Header value for {name!r} must not contain control characters (except tab)")
|
|
@@ -2,11 +2,6 @@ import modal.secret
|
|
|
2
2
|
import modal_proto.api_pb2
|
|
3
3
|
import typing
|
|
4
4
|
|
|
5
|
-
def _header_value_has_invalid_chars(value: str) -> bool: ...
|
|
6
|
-
def _template_references_key(template: str) -> bool:
|
|
7
|
-
"""Whether a header value template references a `$KEY`."""
|
|
8
|
-
...
|
|
9
|
-
|
|
10
5
|
class _HeaderReplacement:
|
|
11
6
|
"""_HeaderReplacement(domain: 'str', headers: 'dict[str, str]', secret: '_Secret | None')"""
|
|
12
7
|
|
|
@@ -42,7 +37,8 @@ class _OutboundPolicy:
|
|
|
42
37
|
"""Immutable configuration for replacing headers in outbound HTTPS requests
|
|
43
38
|
from a Sandbox.
|
|
44
39
|
|
|
45
|
-
|
|
40
|
+
Deprecated, and removed in modal 1.7.0: use `modal.OutboundPolicy` with
|
|
41
|
+
`modal.OutboundRoute.https(..., header_replacements=...)` routes instead.
|
|
46
42
|
|
|
47
43
|
Header values support templating with keys in a replacement's secret: a
|
|
48
44
|
`$`-prefixed key name in the secret is replaced with the secret value.
|
|
@@ -123,7 +119,8 @@ class OutboundPolicy:
|
|
|
123
119
|
"""Immutable configuration for replacing headers in outbound HTTPS requests
|
|
124
120
|
from a Sandbox.
|
|
125
121
|
|
|
126
|
-
|
|
122
|
+
Deprecated, and removed in modal 1.7.0: use `modal.OutboundPolicy` with
|
|
123
|
+
`modal.OutboundRoute.https(..., header_replacements=...)` routes instead.
|
|
127
124
|
|
|
128
125
|
Header values support templating with keys in a replacement's secret: a
|
|
129
126
|
`$`-prefixed key name in the secret is replaced with the secret value.
|
|
@@ -188,3 +185,5 @@ class OutboundPolicy:
|
|
|
188
185
|
def _to_proto(self) -> modal_proto.api_pb2.ExperimentalOutboundPolicy:
|
|
189
186
|
"""Convert to the wire format. Referenced secrets must be hydrated first."""
|
|
190
187
|
...
|
|
188
|
+
|
|
189
|
+
_MAX_HEADER_REPLACEMENTS: "int"
|
|
@@ -708,6 +708,7 @@ class _Image(_Object, type_prefixes=("im",)):
|
|
|
708
708
|
# For internal use only.
|
|
709
709
|
_namespace: "api_pb2.DeploymentNamespace.ValueType" = api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
|
|
710
710
|
_do_assert_no_mount_layers: bool = True,
|
|
711
|
+
_arch: "api_pb2.Arch.ValueType" = api_pb2.ARCH_UNSPECIFIED,
|
|
711
712
|
):
|
|
712
713
|
if base_images is None:
|
|
713
714
|
base_images = {}
|
|
@@ -831,6 +832,7 @@ class _Image(_Object, type_prefixes=("im",)):
|
|
|
831
832
|
build_function=_build_function,
|
|
832
833
|
build_args=build_args,
|
|
833
834
|
volume_mounts=volume_mounts,
|
|
835
|
+
arch=_arch,
|
|
834
836
|
)
|
|
835
837
|
|
|
836
838
|
req = api_pb2.ImageGetOrCreateRequest(
|
|
@@ -2366,6 +2368,8 @@ class _Image(_Object, type_prefixes=("im",)):
|
|
|
2366
2368
|
```
|
|
2367
2369
|
"""
|
|
2368
2370
|
|
|
2371
|
+
arch = kwargs.get("_arch", api_pb2.ARCH_UNSPECIFIED)
|
|
2372
|
+
|
|
2369
2373
|
def context_mount_function(builder_version: ImageBuilderVersion) -> _Mount | None:
|
|
2370
2374
|
return (
|
|
2371
2375
|
_Mount.from_name(
|
|
@@ -2400,6 +2404,7 @@ class _Image(_Object, type_prefixes=("im",)):
|
|
|
2400
2404
|
dockerfile_function=lambda version: DockerfileSpec(commands=[f"FROM {tag}"], context_files={}),
|
|
2401
2405
|
image_registry_config=kwargs.get("image_registry_config"),
|
|
2402
2406
|
force_build=force_build,
|
|
2407
|
+
_arch=arch,
|
|
2403
2408
|
)
|
|
2404
2409
|
|
|
2405
2410
|
def build_python_dockerfile(version: ImageBuilderVersion) -> DockerfileSpec:
|
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
# Copyright Modal Labs 2026
|
|
2
|
+
"""Route-based policy for outbound network traffic from a Sandbox."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import re
|
|
7
|
+
from collections.abc import Mapping, Sequence
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import Any, Literal, cast
|
|
10
|
+
|
|
11
|
+
from modal_proto import api_pb2
|
|
12
|
+
|
|
13
|
+
from ._utils.async_utils import synchronize_api
|
|
14
|
+
from .exception import InvalidError
|
|
15
|
+
from .secret import _Secret
|
|
16
|
+
from .types import OutboundHeaderReplacement
|
|
17
|
+
|
|
18
|
+
_DOMAIN_RE = re.compile(
|
|
19
|
+
r"^(\*\.)?([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\Z"
|
|
20
|
+
)
|
|
21
|
+
_HEADER_NAME_RE = re.compile(r"^[A-Za-z0-9!#$%&'*+.^_`|~-]+\Z")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _is_valid_domain(domain: str) -> bool:
|
|
25
|
+
"""Whether `domain` is a domain name, a `*.`-prefixed wildcard domain, or a bare `*`."""
|
|
26
|
+
return domain == "*" or _DOMAIN_RE.match(domain) is not None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _is_valid_header_name(name: str) -> bool:
|
|
30
|
+
return _HEADER_NAME_RE.match(name) is not None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _header_value_has_invalid_chars(value: str) -> bool:
|
|
34
|
+
return any((ord(c) < 0x20 and c != "\t") or ord(c) == 0x7F for c in value)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _template_references_key(template: str) -> bool:
|
|
38
|
+
"""Whether a header value template references a `$KEY`."""
|
|
39
|
+
i = template.find("$")
|
|
40
|
+
while i != -1 and i + 1 < len(template):
|
|
41
|
+
c = template[i + 1]
|
|
42
|
+
if c == "$":
|
|
43
|
+
i = template.find("$", i + 2)
|
|
44
|
+
continue
|
|
45
|
+
if c.isascii() and (c.isalpha() or c == "_"):
|
|
46
|
+
return True
|
|
47
|
+
i = template.find("$", i + 1)
|
|
48
|
+
return False
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
_RouteKind = Literal["tls", "https", "ip", "any"]
|
|
52
|
+
_ROUTE_KIND_NAMES = {"tls": "TLS", "https": "HTTPS", "ip": "IP", "any": "OutboundRoute.any()"}
|
|
53
|
+
|
|
54
|
+
_HEADER_REPLACEMENT_KEYS = frozenset({"headers", "secret"})
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass(frozen=True)
|
|
58
|
+
class _RouteHeaderReplacement:
|
|
59
|
+
headers: dict[str, str]
|
|
60
|
+
secret: _Secret | None
|
|
61
|
+
unknown_keys: tuple[str, ...] = ()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _string_list(value: Sequence[str], arg_name: str) -> tuple[str, ...]:
|
|
65
|
+
if isinstance(value, str):
|
|
66
|
+
raise InvalidError(f"`{arg_name}` must be a list of strings, not a single string")
|
|
67
|
+
try:
|
|
68
|
+
return tuple(value)
|
|
69
|
+
except TypeError:
|
|
70
|
+
raise InvalidError(f"`{arg_name}` must be a list of strings, got {type(value).__name__}") from None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _normalize_header_replacement(replacement: OutboundHeaderReplacement) -> _RouteHeaderReplacement:
|
|
74
|
+
"""Check the shape and types of a header replacement. The values are checked by `_validate`."""
|
|
75
|
+
# Read as a plain mapping: at runtime the argument may not match its annotation.
|
|
76
|
+
raw = cast(Mapping[str, object], replacement)
|
|
77
|
+
if not isinstance(raw, Mapping):
|
|
78
|
+
raise InvalidError("Each header replacement must be a dict with a `headers` key and an optional `secret` key")
|
|
79
|
+
headers = raw.get("headers")
|
|
80
|
+
if headers is not None and not isinstance(headers, Mapping):
|
|
81
|
+
raise InvalidError(f"`headers` must be a dict of header names to values, got {type(headers).__name__}")
|
|
82
|
+
secret = raw.get("secret")
|
|
83
|
+
if secret is not None and not isinstance(secret, _Secret):
|
|
84
|
+
raise InvalidError(f"`secret` must be a `modal.Secret`, got {type(secret).__name__}")
|
|
85
|
+
return _RouteHeaderReplacement(
|
|
86
|
+
headers=dict(headers) if headers is not None else {},
|
|
87
|
+
secret=secret,
|
|
88
|
+
unknown_keys=tuple(sorted(str(k) for k in raw if k not in _HEADER_REPLACEMENT_KEYS)),
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class _OutboundRoute:
|
|
93
|
+
"""A route in an `OutboundPolicy`: which outbound traffic it matches.
|
|
94
|
+
|
|
95
|
+
Create routes with the `OutboundRoute.tls`, `OutboundRoute.https`,
|
|
96
|
+
`OutboundRoute.ip` and `OutboundRoute.any` factories. Traffic a route
|
|
97
|
+
matches goes to its original destination, except that the `any` route can
|
|
98
|
+
block what it matches. Routes are immutable: `block()` returns a new route.
|
|
99
|
+
|
|
100
|
+
Examples:
|
|
101
|
+
```python
|
|
102
|
+
import modal
|
|
103
|
+
|
|
104
|
+
# Allow TLS connections to a domain and its subdomains.
|
|
105
|
+
modal.OutboundRoute.tls(domains=["example.com", "*.example.com"])
|
|
106
|
+
|
|
107
|
+
# Block everything no earlier route matched.
|
|
108
|
+
modal.OutboundRoute.any().block()
|
|
109
|
+
```
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
_kind: _RouteKind
|
|
113
|
+
_domains: tuple[str, ...]
|
|
114
|
+
_cidrs: tuple[str, ...]
|
|
115
|
+
_header_replacements: tuple[_RouteHeaderReplacement, ...]
|
|
116
|
+
_block: bool
|
|
117
|
+
|
|
118
|
+
def __init__(self, *args, **kwargs):
|
|
119
|
+
"""mdmd:hidden"""
|
|
120
|
+
raise InvalidError(
|
|
121
|
+
"OutboundRoute has no constructor. Use `OutboundRoute.tls`, `OutboundRoute.https`, "
|
|
122
|
+
"`OutboundRoute.ip` or `OutboundRoute.any` instead."
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
@classmethod
|
|
126
|
+
def _new(
|
|
127
|
+
cls,
|
|
128
|
+
kind: _RouteKind,
|
|
129
|
+
*,
|
|
130
|
+
domains: tuple[str, ...] = (),
|
|
131
|
+
cidrs: tuple[str, ...] = (),
|
|
132
|
+
header_replacements: tuple[_RouteHeaderReplacement, ...] = (),
|
|
133
|
+
block: bool = False,
|
|
134
|
+
) -> _OutboundRoute:
|
|
135
|
+
route = cls.__new__(cls)
|
|
136
|
+
route._kind = kind
|
|
137
|
+
route._domains = domains
|
|
138
|
+
route._cidrs = cidrs
|
|
139
|
+
route._header_replacements = header_replacements
|
|
140
|
+
route._block = block
|
|
141
|
+
return route
|
|
142
|
+
|
|
143
|
+
def __repr__(self) -> str:
|
|
144
|
+
# Header replacements are left out: their values can be secret material.
|
|
145
|
+
if self._kind in ("tls", "https"):
|
|
146
|
+
args = f"domains={list(self._domains)!r}"
|
|
147
|
+
elif self._kind == "ip":
|
|
148
|
+
args = f"cidrs={list(self._cidrs)!r}"
|
|
149
|
+
else:
|
|
150
|
+
args = ""
|
|
151
|
+
return f"OutboundRoute.{self._kind}({args})" + (".block()" if self._block else "")
|
|
152
|
+
|
|
153
|
+
@classmethod
|
|
154
|
+
def tls(cls, *, domains: Sequence[str]) -> _OutboundRoute:
|
|
155
|
+
"""Match connections that carry TLS from the first byte to one of `domains`, on tcp/443.
|
|
156
|
+
|
|
157
|
+
Connections are matched by the domain the client requests during the TLS
|
|
158
|
+
handshake (SNI). TLS routes never decrypt traffic: the connection's
|
|
159
|
+
contents are passed through as-is. Traffic to these domains on other
|
|
160
|
+
ports or transports isn't matched by this route.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
domains: Domains to match. A `*.` prefix matches subdomains at any
|
|
164
|
+
depth but not the domain itself: `*.example.com` matches
|
|
165
|
+
`a.example.com` and `a.b.example.com`, not `example.com`. A bare
|
|
166
|
+
`"*"` matches all domains.
|
|
167
|
+
"""
|
|
168
|
+
return cls._new("tls", domains=_string_list(domains, "domains"))
|
|
169
|
+
|
|
170
|
+
@classmethod
|
|
171
|
+
def https(
|
|
172
|
+
cls,
|
|
173
|
+
*,
|
|
174
|
+
domains: Sequence[str],
|
|
175
|
+
header_replacements: Sequence[OutboundHeaderReplacement] | None = None,
|
|
176
|
+
) -> _OutboundRoute:
|
|
177
|
+
"""Match HTTPS connections to one of `domains`, on tcp/443.
|
|
178
|
+
|
|
179
|
+
HTTPS routes always decrypt traffic, which requires the policy to be
|
|
180
|
+
created with `allow_tls_decryption=True`, even when the route has no
|
|
181
|
+
header replacements. Requests whose `Host` header doesn't match the domain
|
|
182
|
+
requested for the connection are refused. Traffic to these domains on
|
|
183
|
+
other ports or transports isn't matched by this route.
|
|
184
|
+
|
|
185
|
+
Header values support templating with keys in a replacement's `secret`:
|
|
186
|
+
a `$`-prefixed key name in the secret is replaced with the secret value.
|
|
187
|
+
Literal `$` characters are written `$$`. Secret values never enter the
|
|
188
|
+
Sandbox: they are injected into matching requests outside the container.
|
|
189
|
+
|
|
190
|
+
Args:
|
|
191
|
+
domains: Domains to match. A `*.` prefix matches subdomains at any
|
|
192
|
+
depth but not the domain itself: `*.example.com` matches
|
|
193
|
+
`a.example.com` and `a.b.example.com`, not `example.com`. A bare
|
|
194
|
+
`"*"` matches all domains.
|
|
195
|
+
header_replacements: Headers to set on matching requests, in public
|
|
196
|
+
beta. Each entry is a dict with a `headers` key (header name ->
|
|
197
|
+
value template) and an optional `secret` key: a named Secret
|
|
198
|
+
(e.g. from `Secret.from_name`) whose keys the header values may
|
|
199
|
+
reference.
|
|
200
|
+
Each header is set on every matching request, so the request
|
|
201
|
+
has exactly one header with that name and the given value.
|
|
202
|
+
Copies the request already has are removed, whatever their
|
|
203
|
+
case, and the header is added if the request has none. A route
|
|
204
|
+
can set each header name only once, ignoring case.
|
|
205
|
+
|
|
206
|
+
Examples:
|
|
207
|
+
```python
|
|
208
|
+
secret = modal.Secret.from_name("api-token")
|
|
209
|
+
|
|
210
|
+
route = modal.OutboundRoute.https(
|
|
211
|
+
domains=["api.example.com"],
|
|
212
|
+
header_replacements=[
|
|
213
|
+
{"secret": secret, "headers": {"Authorization": "Bearer $API_TOKEN"}},
|
|
214
|
+
],
|
|
215
|
+
)
|
|
216
|
+
```
|
|
217
|
+
"""
|
|
218
|
+
return cls._new(
|
|
219
|
+
"https",
|
|
220
|
+
domains=_string_list(domains, "domains"),
|
|
221
|
+
header_replacements=tuple(_normalize_header_replacement(r) for r in header_replacements or ()),
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
@classmethod
|
|
225
|
+
def ip(cls, *, cidrs: Sequence[str]) -> _OutboundRoute:
|
|
226
|
+
"""Match all traffic to one of `cidrs`, on any transport and port.
|
|
227
|
+
|
|
228
|
+
Args:
|
|
229
|
+
cidrs: CIDR ranges to match, e.g. `"203.0.113.0/24"`.
|
|
230
|
+
"""
|
|
231
|
+
return cls._new("ip", cidrs=_string_list(cidrs, "cidrs"))
|
|
232
|
+
|
|
233
|
+
@classmethod
|
|
234
|
+
def any(cls) -> _OutboundRoute:
|
|
235
|
+
"""Match all traffic that no earlier route in the policy matched.
|
|
236
|
+
|
|
237
|
+
Every `OutboundPolicy` needs exactly one `any` route, as its last
|
|
238
|
+
route. Without a redirect, the traffic it matches goes to its original
|
|
239
|
+
destination; call `.block()` on the route to block it instead.
|
|
240
|
+
"""
|
|
241
|
+
return cls._new("any")
|
|
242
|
+
|
|
243
|
+
def block(self) -> _OutboundRoute:
|
|
244
|
+
"""Return a new route that blocks the traffic it matches.
|
|
245
|
+
|
|
246
|
+
Only `OutboundRoute.any()` supports `block()`.
|
|
247
|
+
"""
|
|
248
|
+
if self._kind != "any":
|
|
249
|
+
raise InvalidError(f"{_ROUTE_KIND_NAMES[self._kind]} routes don't support `block()`")
|
|
250
|
+
if self._block:
|
|
251
|
+
raise InvalidError("This route already blocks the traffic it matches")
|
|
252
|
+
return _OutboundRoute._new(self._kind, block=True)
|
|
253
|
+
|
|
254
|
+
def _validate(self, *, allow_tls_decryption: bool) -> None:
|
|
255
|
+
kind_name = _ROUTE_KIND_NAMES[self._kind]
|
|
256
|
+
if self._kind in ("tls", "https"):
|
|
257
|
+
if not self._domains:
|
|
258
|
+
raise InvalidError(f"{kind_name} routes must have at least one domain")
|
|
259
|
+
for domain in self._domains:
|
|
260
|
+
if not isinstance(domain, str) or not _is_valid_domain(domain):
|
|
261
|
+
raise InvalidError(f"Invalid domain: {domain!r}")
|
|
262
|
+
if self._kind == "https" and not allow_tls_decryption:
|
|
263
|
+
raise InvalidError("HTTPS routes require `allow_tls_decryption=True` on the `OutboundPolicy`")
|
|
264
|
+
if self._kind == "ip":
|
|
265
|
+
if not self._cidrs:
|
|
266
|
+
raise InvalidError("IP routes must have at least one CIDR")
|
|
267
|
+
for cidr in self._cidrs:
|
|
268
|
+
if not isinstance(cidr, str) or not cidr:
|
|
269
|
+
raise InvalidError(f"Invalid CIDR: {cidr!r}")
|
|
270
|
+
header_names: set[str] = set()
|
|
271
|
+
for replacement in self._header_replacements:
|
|
272
|
+
if replacement.unknown_keys:
|
|
273
|
+
raise InvalidError(
|
|
274
|
+
f"Unknown key(s) in header replacement: {', '.join(replacement.unknown_keys)}; "
|
|
275
|
+
"expected `headers` and optionally `secret`"
|
|
276
|
+
)
|
|
277
|
+
if not replacement.headers:
|
|
278
|
+
raise InvalidError("`headers` must contain at least one header")
|
|
279
|
+
secret = replacement.secret
|
|
280
|
+
for name, value in replacement.headers.items():
|
|
281
|
+
if not isinstance(name, str) or not _is_valid_header_name(name):
|
|
282
|
+
raise InvalidError(f"Invalid header name: {name!r}")
|
|
283
|
+
if name.lower() in header_names:
|
|
284
|
+
raise InvalidError(f"Header {name!r} is set more than once in the route")
|
|
285
|
+
header_names.add(name.lower())
|
|
286
|
+
if not isinstance(value, str):
|
|
287
|
+
raise InvalidError(f"Header value for {name!r} must be a string")
|
|
288
|
+
if _header_value_has_invalid_chars(value):
|
|
289
|
+
raise InvalidError(f"Header value for {name!r} must not contain control characters (except tab)")
|
|
290
|
+
if secret is None and _template_references_key(value):
|
|
291
|
+
raise InvalidError(f"Header value for {name!r} references a secret key, but no `secret` was passed")
|
|
292
|
+
if secret is not None and secret._is_ephemeral:
|
|
293
|
+
raise InvalidError(
|
|
294
|
+
"Outbound policies only support named secrets (e.g. `Secret.from_name`); "
|
|
295
|
+
"ephemeral secrets (e.g. `Secret.from_dict`) are not yet supported"
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
class _OutboundPolicy:
|
|
300
|
+
"""Routes that control where outbound network traffic from a Sandbox goes.
|
|
301
|
+
|
|
302
|
+
A policy is an ordered list of `OutboundRoute`s. Each outbound connection is
|
|
303
|
+
handled by the first route that matches it, and goes to its original
|
|
304
|
+
destination. The last route must be `OutboundRoute.any()`, which matches
|
|
305
|
+
everything no earlier route matched and either lets it through or, with
|
|
306
|
+
`.block()`, blocks it.
|
|
307
|
+
|
|
308
|
+
Examples:
|
|
309
|
+
```python
|
|
310
|
+
import modal
|
|
311
|
+
|
|
312
|
+
secret = modal.Secret.from_name("api-token")
|
|
313
|
+
|
|
314
|
+
policy = modal.OutboundPolicy(
|
|
315
|
+
allow_tls_decryption=True,
|
|
316
|
+
routes=[
|
|
317
|
+
# Inject a secret-backed header into HTTPS requests.
|
|
318
|
+
modal.OutboundRoute.https(
|
|
319
|
+
domains=["api.example.com"],
|
|
320
|
+
header_replacements=[{"secret": secret, "headers": {"Authorization": "Bearer $API_TOKEN"}}],
|
|
321
|
+
),
|
|
322
|
+
# Allow TLS connections to these domains.
|
|
323
|
+
modal.OutboundRoute.tls(domains=["github.com", "*.github.com", "pypi.org"]),
|
|
324
|
+
# Allow all traffic to a CIDR range.
|
|
325
|
+
modal.OutboundRoute.ip(cidrs=["203.0.113.0/24"]),
|
|
326
|
+
# Block everything else.
|
|
327
|
+
modal.OutboundRoute.any().block(),
|
|
328
|
+
],
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
sb = modal.Sandbox.create(app=app, outbound_policy=policy)
|
|
332
|
+
```
|
|
333
|
+
"""
|
|
334
|
+
|
|
335
|
+
_allow_tls_decryption: bool
|
|
336
|
+
_routes: tuple[_OutboundRoute, ...]
|
|
337
|
+
|
|
338
|
+
def __init__(self, *, allow_tls_decryption: bool = False, routes: Sequence[_OutboundRoute]):
|
|
339
|
+
"""Create an outbound policy.
|
|
340
|
+
|
|
341
|
+
Args:
|
|
342
|
+
allow_tls_decryption: Allow Modal to decrypt the Sandbox's TLS traffic on
|
|
343
|
+
routes that need it, by generating a certificate authority for the
|
|
344
|
+
Sandbox and attempting to make the Sandbox trust it. Decrypts nothing
|
|
345
|
+
on its own. Required by HTTPS routes. Fixed when the Sandbox is created.
|
|
346
|
+
Sandboxes that allow TLS decryption don't support memory snapshots.
|
|
347
|
+
routes: Ordered routes; the first route that matches a connection
|
|
348
|
+
handles it. Must end with `OutboundRoute.any()`.
|
|
349
|
+
"""
|
|
350
|
+
self._allow_tls_decryption = allow_tls_decryption
|
|
351
|
+
self._routes = tuple(routes)
|
|
352
|
+
|
|
353
|
+
def _validate(self) -> None:
|
|
354
|
+
"""Check the policy, raising `InvalidError` on the first violation found."""
|
|
355
|
+
if not isinstance(self._allow_tls_decryption, bool):
|
|
356
|
+
raise InvalidError("`allow_tls_decryption` must be a bool")
|
|
357
|
+
if not self._routes:
|
|
358
|
+
raise InvalidError("`routes` must contain at least one route")
|
|
359
|
+
for route in self._routes:
|
|
360
|
+
if not isinstance(route, _OutboundRoute):
|
|
361
|
+
raise InvalidError(f"`routes` must contain only `OutboundRoute`s, got {type(route).__name__}")
|
|
362
|
+
any_routes = [i for i, route in enumerate(self._routes) if route._kind == "any"]
|
|
363
|
+
if not any_routes:
|
|
364
|
+
raise InvalidError("The last route must be `OutboundRoute.any()`")
|
|
365
|
+
if len(any_routes) > 1:
|
|
366
|
+
raise InvalidError("`routes` can contain only one `OutboundRoute.any()`")
|
|
367
|
+
if any_routes[0] != len(self._routes) - 1:
|
|
368
|
+
raise InvalidError("`OutboundRoute.any()` must be the last route")
|
|
369
|
+
for route in self._routes:
|
|
370
|
+
route._validate(allow_tls_decryption=self._allow_tls_decryption)
|
|
371
|
+
|
|
372
|
+
def _secrets(self) -> list[_Secret]:
|
|
373
|
+
"""Deduplicated list of secrets referenced by header replacements."""
|
|
374
|
+
return list(
|
|
375
|
+
dict.fromkeys(
|
|
376
|
+
r.secret for route in self._routes for r in route._header_replacements if r.secret is not None
|
|
377
|
+
)
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
def _to_proto(self) -> api_pb2.OutboundPolicy:
|
|
381
|
+
"""Convert to the wire format. Referenced secrets must be hydrated first."""
|
|
382
|
+
P = api_pb2.OutboundPolicy
|
|
383
|
+
|
|
384
|
+
# A local helper keeps nested proto types out of the module's generated type stub.
|
|
385
|
+
def route_proto(route: _OutboundRoute) -> api_pb2.OutboundPolicy.Route:
|
|
386
|
+
if route._kind == "tls":
|
|
387
|
+
return P.Route(tls=P.TLSRoute(domains=route._domains))
|
|
388
|
+
if route._kind == "https":
|
|
389
|
+
header_replacements = [
|
|
390
|
+
P.HeaderReplacement(
|
|
391
|
+
secret_id=r.secret.object_id if r.secret is not None else "",
|
|
392
|
+
headers=r.headers,
|
|
393
|
+
)
|
|
394
|
+
for r in route._header_replacements
|
|
395
|
+
]
|
|
396
|
+
return P.Route(https=P.HTTPSRoute(domains=route._domains, header_replacements=header_replacements))
|
|
397
|
+
if route._kind == "ip":
|
|
398
|
+
return P.Route(ip=P.IPRoute(cidrs=route._cidrs))
|
|
399
|
+
redirect = P.Redirect(block=P.Redirect.Block()) if route._block else None
|
|
400
|
+
return P.Route(any=P.AnyRoute(redirect=redirect))
|
|
401
|
+
|
|
402
|
+
return P(
|
|
403
|
+
tls_decryption=P.TLSDecryption(allowed=self._allow_tls_decryption),
|
|
404
|
+
routes=[route_proto(route) for route in self._routes],
|
|
405
|
+
)
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
def _validate_outbound_policy_compatibility(
|
|
409
|
+
outbound_policy: _OutboundPolicy | None,
|
|
410
|
+
*,
|
|
411
|
+
block_network: bool,
|
|
412
|
+
outbound_cidr_allowlist: Sequence[str] | None,
|
|
413
|
+
outbound_domain_allowlist: Sequence[str] | None,
|
|
414
|
+
experimental_outbound_policy: Any,
|
|
415
|
+
) -> None:
|
|
416
|
+
"""Reject Sandbox options that conflict with `outbound_policy`."""
|
|
417
|
+
if outbound_policy is None:
|
|
418
|
+
return
|
|
419
|
+
if block_network:
|
|
420
|
+
raise InvalidError(
|
|
421
|
+
"`outbound_policy` cannot be used when `block_network` is enabled; "
|
|
422
|
+
"end the policy's routes with `OutboundRoute.any().block()` instead"
|
|
423
|
+
)
|
|
424
|
+
if outbound_cidr_allowlist is not None:
|
|
425
|
+
raise InvalidError(
|
|
426
|
+
"`outbound_policy` cannot be used with `outbound_cidr_allowlist`; "
|
|
427
|
+
"use an `OutboundRoute.ip(cidrs=[...])` route, followed by `OutboundRoute.any().block()`, instead"
|
|
428
|
+
)
|
|
429
|
+
if outbound_domain_allowlist is not None:
|
|
430
|
+
raise InvalidError(
|
|
431
|
+
"`outbound_policy` cannot be used with `outbound_domain_allowlist`; "
|
|
432
|
+
"use an `OutboundRoute.tls(domains=[...])` route, followed by `OutboundRoute.any().block()`, instead"
|
|
433
|
+
)
|
|
434
|
+
if experimental_outbound_policy is not None:
|
|
435
|
+
raise InvalidError(
|
|
436
|
+
"`outbound_policy` cannot be used with `_experimental_outbound_policy`; "
|
|
437
|
+
"use `OutboundRoute.https(domains=[...], header_replacements=[...])` routes "
|
|
438
|
+
"in a policy with `allow_tls_decryption=True` instead"
|
|
439
|
+
)
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
OutboundRoute = synchronize_api(_OutboundRoute)
|
|
443
|
+
OutboundPolicy = synchronize_api(_OutboundPolicy)
|