add unrestricted stdlib symbols to Yaegi interpreter

os/exec lives in yaegi's stdlib/unrestricted package, not the default
stdlib.Symbols. Without it, extensions importing os/exec fail with
'unable to find source'. This is needed for the /run command example
and any extension that spawns subprocesses.
This commit is contained in:
Ed Zynda
2026-02-27 00:43:31 +03:00
parent 6ac8d3983a
commit fb3608326f
+6 -1
View File
@@ -9,6 +9,7 @@ import (
"github.com/charmbracelet/log"
"github.com/traefik/yaegi/interp"
"github.com/traefik/yaegi/stdlib"
"github.com/traefik/yaegi/stdlib/unrestricted"
)
// Discovery paths searched in order (lowest to highest precedence):
@@ -146,10 +147,14 @@ func loadSingleExtension(path string) (*LoadedExtension, error) {
// Create a fresh interpreter.
i := interp.New(interp.Options{})
// Expose a safe subset of the Go stdlib.
// Expose the Go stdlib. The base set covers most packages; the
// unrestricted set adds os/exec so extensions can spawn processes.
if err := i.Use(stdlib.Symbols); err != nil {
return nil, fmt.Errorf("loading stdlib symbols: %w", err)
}
if err := i.Use(unrestricted.Symbols); err != nil {
return nil, fmt.Errorf("loading unrestricted symbols: %w", err)
}
// Expose KIT's extension API types so the extension can
// import "kit/ext" and use ext.ToolCall, ext.API, etc.