Can scripts written in Python run within a WebExtension?
WebExtension is basically a web application with access to some special browser API.
This is how people using TypeScript or even Scala can write web application.
However, it may bring some overhead depending on what you are trying to do so often it’s not a good idea. It’s best to discuss it with experts.
I remember some Mozilla project about running Python in the browser using WebAssembly: