It's hard to answer this question without knowing what functionality you are trying to achieve. Specifically:
- The rules (technical and CWS policy) specifically forbid using anything like eval() (including Function constructor, inline scripts, inline scripts injected via Element.innerHTML or anything which will fail to load/execute with CSP containing only "safe" keywords)
- You can execute arbitrary code within a sandbox and send over arbitrary result. The rest of extension (e.g., content script) can act on this arbitrary result
- Query selectors are considered data and textual/numeric/JSON data is just data (not code). So are media files like images, soundtracks, video, even PDF files.
If you consider point 2 and 3 carefully, you'll notice that extensions do have a way to execute remote code in a Turing-complete way, as long as the Turing-complete thing stays in the sandbox. For example, extension content script can receive from "remote source" (literal server online, or native host, or "remote code" executed in a sandbox) an arbitrary query selector (call it
sel) and arbitrary text data (call it
text) and execute the following:
document.querySelector(sel).textContent = text; . Put enough of these on the page via content script and you basically have a remote code execution in a controlled manner. That is the entire point of the sandbox. You just need to make sure you and reviewer can reason about the actual behavior of the code and maintain some boundaries yourself.