Skip to content

Add build sandboxing for package compilation#1371

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/add-sandbox-for-package-building
Draft

Add build sandboxing for package compilation#1371
Copilot wants to merge 4 commits intomainfrom
copilot/add-sandbox-for-package-building

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 6, 2026

Package builds currently run with full host system access, creating security risks: packages can modify the developer machine and pull incorrect host dependencies.

Implementation

Sandbox wrapper (scripts/build-sandbox.sh)

  • Uses Linux namespaces (mount, UTS, IPC, PID) via unshare when available
  • Falls back to passthrough on macOS and restricted environments
  • Configurable via OPENWRT_SANDBOX_METHOD environment variable

Build system integration

  • Wraps Build/Compile, Build/Install (package-defaults.mk)
  • Wraps Host/Compile (host-build.mk)
  • Uses $(if $(BUILD_SANDBOX),$(BUILD_SANDBOX) env) pattern to handle variable assignments

Configuration

  • CONFIG_BUILD_SANDBOX option in menuconfig (default: enabled)
  • Disable with CONFIG_BUILD_SANDBOX=n in .config

Example

Before:

define Build/Compile/Default
	+$(MAKE_VARS) $(MAKE) -C $(PKG_BUILD_DIR) $(MAKE_FLAGS)
endef

After:

define Build/Compile/Default
	+$(if $(BUILD_SANDBOX),$(BUILD_SANDBOX) env )$(MAKE_VARS) $(MAKE) -C $(PKG_BUILD_DIR) $(MAKE_FLAGS)
endef

When enabled, compilation runs: build-sandbox.sh env CC=gcc CFLAGS="..." make

When disabled, runs normally: CC=gcc CFLAGS="..." make

Platform Support

  • Linux: Full namespace isolation with graceful degradation
  • macOS: Passthrough (namespaces unavailable)
  • Restricted environments: Automatic fallback to passthrough

No package Makefile changes required.

Original prompt

Please analyze how packages are built and add a sandbox or chroot around the compilation and building steps. Right now it's a security issues a building problem, packages could modify the developer machine but also pull in wrong dependencies. The solution should be compatible with both Linux and macOS, if macOS is not possible, skip it.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 6, 2026 06:50
- Created build-sandbox.sh wrapper script with namespace isolation for Linux
- Added fallback environment isolation for restricted environments and macOS
- Integrated sandbox into Build/Compile and Build/Install in package-defaults.mk
- Integrated sandbox into Host/Compile in host-build.mk
- Added CONFIG_BUILD_SANDBOX configuration option (default enabled)
- Sandbox provides isolation to prevent host system modifications and dependency issues

Co-authored-by: aparcar <16000931+aparcar@users.noreply.github.com>
- Created BUILD_SANDBOX.md with comprehensive documentation
- Tested sandbox with make commands and compilation
- Verified sandbox can be disabled via CONFIG_BUILD_SANDBOX
- Confirmed backward compatibility when sandbox is disabled

Co-authored-by: aparcar <16000931+aparcar@users.noreply.github.com>
- Fixed environment variable handling: sandbox now preserves all environment properly
- Fixed Make syntax when BUILD_SANDBOX is disabled using $(if) conditionals
- Added 'env' wrapper to properly handle MAKE_VARS environment variable assignments
- Simplified environment isolation to just pass through all arguments
- Tested both enabled and disabled sandbox configurations

Co-authored-by: aparcar <16000931+aparcar@users.noreply.github.com>
Copilot AI changed the title [WIP] Add sandbox around package building steps for security Add build sandboxing for package compilation Jan 6, 2026
Copilot AI requested a review from aparcar January 6, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants