Edit file from LXC container via gedit or pluma

I would like to know how to edit files in LXC containers via a gui app such as gedit or pluma. I usually use sftp with in caja to open the LXD host and go under /var/lib/lxd/containers to get where I want. However after editing the file and saving it, the file permissions are messed up. Even when I copy files to the container this way, via caja. The file saved is not editable by the root user from a terminal.

I know the preferred way is to have a shared folder between your desktop and LXD host, and then use LXC push.

Is there a way we can browse and edit via sftp from the LXD host? With gui apps?

You should never directly modify files under /var/lib/lxd/containers.

You should be able to do something like EDITOR=gedit lxc file edit blah/etc/hosts to edit /etc/hosts from the blah container in gedit. This uses the LXD API so can be run on any system that has remote LXD access to the target.