Package for running executables embedded in a Go binary
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-03-07 08:22:26 -05:00
examples exec.Cmd, fdexec.Cmd: optionally enable debug log 2023-01-13 09:44:10 -05:00
exec exec,fdexec: filter internal environment variables 2025-04-20 08:18:06 -04:00
fdexec exec,fdexec: filter internal environment variables 2025-04-20 08:18:06 -04:00
internal/reexec exec,fdexec: filter internal environment variables 2025-04-20 08:18:06 -04:00
.gitignore gitignore: cleanup 2022-12-13 06:57:46 -05:00
embedexe.go embedexe.FromInt: return nil if fd is invalid 2023-01-14 08:10:53 -05:00
embedexe_test.go test: cleanup 2023-01-19 08:07:33 -05:00
go.mod chore: update deps 2026-03-05 07:39:29 -05:00
go.sum chore: update deps 2026-03-05 07:39:29 -05:00
LICENSE doc: update copyright date 2026-03-07 08:22:26 -05:00
README.md doc: README: formatting 2026-03-06 08:41:18 -05:00

embedexe

Go Reference

Run a program stored in a byte array such as an executable or a directory of executables embedded in a Go binary.

LIMITATIONS

  • the executable must either be statically linked or the linked libraries available on the filesystem
  • only works on Linux (but not on ChromeOS/crostini where the W^X policies disable executing memfds)
  • an embedded executable cannot run another executable embedded in the same binary
  • an embedded executable cannot use a library embedded in the same binary

EXAMPLES

Run an embedded executable

// Echotest forks and runs an embedded echo(1).
//
//	cp /bin/echo .
//	go build
//	./echotest hello world
package main

import (
	_ "embed"
	"log"
	"os"

	"codeberg.org/msantos/embedexe/exec"
)

//go:embed echo
var echo []byte

func main() {
	cmd := exec.Command(echo, os.Args[1:]...)

	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	if err := cmd.Run(); err != nil {
		log.Fatalln("run:", cmd, err)
	}
}