from __future__ import annotations import io, os, sys, tarfile, tempfile from pathlib import Path from cryptography.fernet import Fernet import uvicorn bundle = Path(__file__).with_name("runtime.bundle.enc").read_bytes() key = os.environ["CUSTOMER_AI_BUNDLE_KEY"].encode() plain = Fernet(key).decrypt(bundle) root = Path(tempfile.mkdtemp(prefix="astera-customer-ai-")) with tarfile.open(fileobj=io.BytesIO(plain), mode="r:gz") as archive: for member in archive.getmembers(): target = (root / member.name).resolve() if root.resolve() not in target.parents and target != root.resolve(): raise RuntimeError("unsafe_bundle_path") archive.extractall(root) sys.path.insert(0, str(root)) os.chdir(root) from public_app import app if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")