Skip to main content
A ready-to-run example is available here!
The Apptainer sandboxed agent server demonstrates how to run agents in isolated Apptainer containers using ApptainerWorkspace. Apptainer (formerly Singularity) is a container runtime designed for HPC environments that doesn’t require root access, making it ideal for shared computing environments, university clusters, and systems where Docker is not available.

When to Use Apptainer

Use Apptainer instead of Docker when:
  • Running on HPC clusters or shared computing environments
  • Root access is not available
  • Docker daemon cannot be installed
  • Working in academic or research computing environments
  • Security policies restrict Docker usage

Prerequisites

Before running this example, ensure you have:

Basic Apptainer Sandbox Example

This example shows how to create an ApptainerWorkspace that automatically manages Apptainer containers for agent execution:
examples/02_remote_agent_server/08_convo_with_apptainer_sandboxed_server.py
You can run the example code as-is.
The model name should follow the LiteLLM convention: provider/model_name (e.g., anthropic/claude-sonnet-4-5-20250929, openai/gpt-4o). The LLM_API_KEY should be the API key for your chosen provider.
ChatGPT Plus/Pro subscribers: You can use LLM.subscription_login() to authenticate with your ChatGPT account and access Codex models without consuming API credits. See the LLM Subscriptions guide for details.

Configuration Options

The ApptainerWorkspace supports several configuration options: Use a pre-built agent server image for fastest startup:

Option 2: Build from Base Image

Build from a base image when you need custom dependencies:
Building from a base image requires internet access and may take several minutes on first run. The built image is cached for subsequent runs.

Option 3: Use Existing SIF File

If you have a pre-built Apptainer SIF file:

Key Features

Rootless Container Execution

Apptainer runs completely without root privileges:
  • No daemon process required
  • User namespace isolation
  • Compatible with most HPC security policies

Image Caching

Apptainer automatically caches container images:
  • First run builds/pulls the image
  • Subsequent runs reuse cached SIF files
  • Cache location: ~/.cache/apptainer/

Port Mapping

The workspace exposes ports for agent services:

Differences from Docker

While the API is similar to DockerWorkspace, there are some differences:

Troubleshooting

Apptainer Not Found

If you see apptainer: command not found:
  1. Install Apptainer following the official guide
  2. Ensure it’s in your PATH: which apptainer

Permission Errors

Apptainer should work without root. If you see permission errors:
  • Check that your user has access to /tmp
  • Verify Apptainer is properly installed: apptainer version
  • Ensure the cache directory is writable: ls -la ~/.cache/apptainer/

Next Steps