How to detect lxd from inside container?

is there a way to identify, for a script, that we are running inside a lxd container?

I’d use /dev/lxd

Note that /dev/lxd may go away if security.devlxd is set to false

In such case, you can’t really detect LXD, but you can still detect that it’s an LXC container by looking at /proc/1/environ for the container= variable that we pass to the init system.