Custom Templates
Overview
Section titled “Overview”You can create custom AgentBox templates that include MCP Gateway pre-installed. This allows you to have a base template with MCP Gateway ready to use, and then add your own customizations.
Create a custom template with MCP Gateway
Section titled “Create a custom template with MCP Gateway”Start with the mcp-gateway template and customize it:
# Initialize a new template
agentbox template init
# Build from mcp-gateway template
agentbox template build --from mcp-gateway --name my-mcp-templateCustomize the template
Section titled “Customize the template”You can customize the template by modifying the Dockerfile:
FROM agentbox/base:latest
# MCP Gateway is already installed in the base template
# Add your custom packages and configurations
RUN apt-get update && apt-get install -y \
your-custom-package \
&& rm -rf /var/lib/apt/lists/*
# Install additional Python packages if needed
RUN pip install your-python-package
# Set up your custom environment
ENV CUSTOM_VAR=value
# Copy custom scripts
COPY scripts/ /usr/local/bin/
RUN chmod +x /usr/local/bin/*.shBuild the template
Section titled “Build the template”Build your custom template:
# Build the template
agentbox template build --name my-mcp-template --platform linux_x86Use your custom template
Section titled “Use your custom template”Use your custom template when creating sandboxes:
from agentbox import Sandbox
# Use your custom template
sandbox = Sandbox.create(
api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxx",
template="your-template-id",
mcp={
"duckduckgo": {}
}
)from agentbox import AsyncSandbox
# Use your custom template
sandbox = await AsyncSandbox.create(
api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxx",
template="your-template-id",
mcp={
"duckduckgo": {}
}
)Template configuration file
Section titled “Template configuration file”You can also configure your template using agentbox.toml:
[template]
name = "my-mcp-template"
description = "Custom template with MCP Gateway"
[build]
platform = "linux_x86"
dockerfile = "Dockerfile"
[env]
CUSTOM_VAR = "value"Best practices
Section titled “Best practices”- Start from mcp-gateway: Use
mcp-gatewayas your base template to ensure MCP Gateway is properly installed - Keep it minimal: Only add what you need to keep build times reasonable
- Test thoroughly: Test your template with various MCP server configurations
- Document dependencies: Clearly document any additional packages or configurations