Hey @lucas.bodnyk welcome to the forums.
You’re totally right to want to avoid running commands on the host OS! A couple of options here: Your container should already have by default the environment variable
BALENA_DEVICE_UUID, of which the first 6 characters is the default hostname.
Secondly, given that it’s possible that the hostname can be changed and may not be static, you could take a look at using the Supervisor API to request the current hostname. In order to use this you have to add a label
io.balena.features.supervisor-api to the container, and then you can use the
GET /v1/device/host-config endpoint to obtain the hostname within your container and set it as an environment variable. Note that there are also methods to change the hostname too, if required.