Vte terminal inside flatpak

I’m developing a program that has a VteTerminal widget in it, and the program can be installed via flatpak, the problem is that flatpak does it’s job an sandboxes the terminal. Does anyone know a way around it?

Add the permission --talk-name=org.freedesktop.Flatpak, then run flatpak-spawn --host some-command to run the given command on the host. You could also use the D-Bus APIs directly via HostCommand, which Builder and Tilix do.

You still need to grab the shell; in the Tilix Flatpak this is done by running getent on the host to retrieve the shell. Looking at what Builder does here would probably be useful as well.

1 Like

It requires effectively breaking out of the sandbox, because once you’re on the host, you can do pretty much anything.

Add this to your Flatpak manifest under finish-args.


When determining what shell to launch for the user, you’ll not be able to rely on the shell information within the Flatpak sandbox. So you’ll need to do something like this to sniff the shell from the host, just like GNOME Builder does.

flatpak-spawn --host getent passwd $USER 
christian:x:1000:1000:Christian Hergert:/home/christian:/bin/bash

Instead of launching /bin/bash, you’ll need to launch it via flatpak-spawn like the following (assuming you’ve setup the PTY for stdin/stdout/stderr on the appropriate FDs).

flatpak-spawn --host --forward-fd=0 --forward-fd=1 --forward-fd=2 /bin/bash

Hope that helps. Builder has abstractions to make all of this stuff easier, but it doesn’t really port well outside of the Builder code-base.

1 Like

Wow, spawning the shell works. I searched Pty documentation and couldn’t find anything on file descriptors. How do I set the appropriate FDs?

I really wish I had the ability to understand anything from Builder’s source code, (tho I always search) I never find what I’m looking for. So I usually end up searching code in some simpler projects like Elementary’s Code or GEdit. But unfortunately none of them are Flatpaks :slightly_frowning_face:

Do you think there would be anything that could be shared with other terminals? Given the nightmare that fixing that Tilix memory corruption has been anyway, I was sort of thinking of making a small library that wraps or maybe derives from libvte to make some of the functions “just work” in a Flatpak environment (or at least as much as they could).

1 Like

Hey quick update, I ran through Builder’s source, I ported the code to Vala and I can now spawn commands on the host. Following what Builder does I create a terminal using the spawn on host function, right now the only thing that I’m struggling with is finding out why my terminal (spawned on the host) is picking up Builder’s terminal tty and not creating a new one :thinking:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.