Bring Your Own Container (BYOC)
Build a custom container image with your dependencies, then run it in Krutrim Cloud Sandbox.
Custom Container Images for Sandbox (BYOC)
Krutrim Cloud Sandbox allows developers and AI agents to use custom container images through the imageUri parameter. Custom images let you pre-install runtime dependencies—such as Python libraries, system binaries, compilers, CLI tools, and model runtimes—so sandboxes can start without installing these dependencies at runtime using apt-get or pip.
Key Benefits
Pre-baked runtime environments: Package dependencies such as
ffmpeg, CUDA, Rust, Go, custom Python libraries, and ML runtimes directly into your image.Faster sandbox provisioning: Avoid installing large packages during sandbox initialization.
Immutable image resolution: When you specify an image tag (for example,
myrepo/image:v1.0), Krutrim Cloud resolves and pins it to its immutable@sha256:...content digest to support auditability and reproducible execution.
Quickstart: Create a Sandbox with a Custom Image
You can provide the image_uri field when creating a sandbox with the official Python SDK (krutrim-client) or the REST API.
Python SDK (krutrim-client)
from krutrim_client import KrutrimClient
with KrutrimClient() as client:
# Creates the sandbox, waits for it to become active,
# and cleans it up when the context exits.
with client.sandbox.create(
image_uri="docker.io/myworkspace/custom-python-ml:v1.0",
region="In-Bangalore-1",
flavor_name="sandbox-small",
timeout=1800,
wait_timeout=300,
) as sandbox:
print(f"Sandbox Provisioned ID: {sandbox.id}")
# Execute a command in the custom environment.
result = sandbox.execute(
"python3 -c 'import torch; print(torch.__version__)'"
)
print(f"Stdout:\n{result.stdout}")REST API (cURL)
Container Requirements and Compatibility Contract
To integrate with Krutrim Cloud Sandbox data-plane APIs—including command execution, file transfers, and port forwarding—a custom container image must comply with the Krutrim Sandbox Agent Contract.
Technical Specifications
CPU architecture
linux/amd64
Multi-architecture images must include an amd64 variant.
Working directory
/app
Project root directory, owned by user ID 1000.
User permissions
User ID 1000 (sandboxuser)
Non-root execution is enforced for sandbox security.
Agent listener port
8871 or 8888
The container entrypoint must start sandbox-agent.
HTTP health and API endpoints
GET /, POST /execute
Required for readiness checks and command execution.
Build a Krutrim-Compatible Custom Image
Server-side Dockerfile builds through the API are not currently supported. Build the image locally or in your CI/CD pipeline using standard Docker tools, then push it to a public container registry before using it in image_uri.
Official Multi-Stage Dockerfile Template
The following multi-stage Dockerfile architecture is based on the custom_image cookbook in the ola-krutrim/Krutrim-client-python repository.
Build, Smoke-Test, and Deploy
1. Prepare the build context
Clone or copy the build context directory containing your Dockerfile and the Sandbox Agent source files in agent/.
2. Build for linux/amd64
3. Smoke-test locally (optional)
Run the container locally and verify that the agent's health endpoint responds.
4. Push the image to a public registry
Push the image to a supported public registry, such as Docker Hub, GitHub Container Registry (GHCR), or Quay.io.
5. Create a sandbox using the Python SDK
Current Scope and Limitations
Troubleshooting BYOC Sandboxes
Sandbox remains in deploying or provisioning times out
Possible cause: The custom image does not contain the Krutrim Sandbox Agent (sandbox-agent), or the agent fails to bind to port 8871 or 8888.
Resolution:
Confirm that the image includes the
sandbox-agentbinary.Verify that the Dockerfile's entrypoint starts
sandbox-agent.Confirm that the agent listens on the required port and that
GET /responds successfully.Rebuild and push the image, then create a new sandbox.
400 Bad Request: Invalid imageUri
Possible causes:
The image URI is malformed or the image is not publicly accessible.
The image does not include a
linux/amd64variant.
Resolution:
Verify that the image can be pulled without authentication:
Confirm that the image supports
linux/amd64.Correct the image URI and retry sandbox creation.
Last updated

