As soon as you're allowing untrusted users to write code that can be run on your systems things get difficult fast. It doesn't matter which database interface you're using.
I'd suggest running a separate copy of PostgreSQL for each user so that they can't disrupt with each other, nor any database that your website "backend" is using. This way, it doesn't matter what users do to their copy, whether they leave any cursors open, locks taken, zero-days exploited, etc. Further, you should probably also isolate each database server in its own VM, so that if they manage to hack it they're not going to get very far. VM software lets you put quotas on CPU, RAM, and disk usage, so one user can't dominate others as well.
Otherwise, if you're happy assuming the user has a recent browser you could run Postgres in their browser, e.g. via WASM, and just copy the data periodically during their session.