Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions go/sandboxaid/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ var log Logger = stdlog.New(os.Stderr, "", stdlog.LstdFlags)

type Handler struct {
http.Handler
client client.Client
client client.Client
defaultImage string
}

func NewHandler(client client.Client) *Handler {
func NewHandler(client client.Client, defaultImage string) *Handler {
r := chi.NewRouter()

h := &Handler{
Handler: r,
client: client,
Handler: r,
client: client,
defaultImage: defaultImage,
}

// Log to stderr.
Expand Down Expand Up @@ -76,6 +78,9 @@ func (h *Handler) v1PostSandbox(w http.ResponseWriter, r *http.Request) {
sendError(w, r, err, http.StatusBadRequest)
return
}
if s.Spec.Image == "" {
s.Spec.Image = h.defaultImage
}

created, err := h.client.CreateSandbox(r.Context(), space, &s)
if err != nil {
Expand Down
11 changes: 10 additions & 1 deletion go/sandboxaid/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
"github.com/substratusai/sandboxai/go/sandboxaid/handler"
)

const (
defaultDefaultImage = "substratusai/sandboxai-box:v0.2.0"
)

func main() {
host, ok := os.LookupEnv("SANDBOXAID_HOST")
if !ok {
Expand All @@ -41,6 +45,11 @@ func main() {
deleteOnShutdown = strings.ToLower(strings.TrimSpace(val)) == "true"
}

defaultImage, ok := os.LookupEnv("SANDBOXAID_DEFAULT_IMAGE")
if !ok {
defaultImage = defaultDefaultImage
}

log := log.New(os.Stderr, "", log.LstdFlags)
handler.SetLogger(log)
docker.SetLogger(log)
Expand Down Expand Up @@ -86,7 +95,7 @@ func main() {

server := &http.Server{
Addr: fmt.Sprintf("%s:%s", host, port),
Handler: handler.NewHandler(client),
Handler: handler.NewHandler(client, defaultImage),
}

go func() {
Expand Down
4 changes: 1 addition & 3 deletions python/sandboxai/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

log = getLogger(__name__)

DEFAULT_IMAGE = "substratusai/sandboxai-box:v0.2.0"

# Prevent multiple Sandbox() instances from attempting to start the
# embedded server at the same time.
embedded_mutex = Lock()
Expand All @@ -35,7 +33,7 @@ def __init__(
lazy_create: bool = False,
space: str = "default",
name: str = None,
image: str = DEFAULT_IMAGE,
image: str = None,
env: dict = None,
):
"""
Expand Down
19 changes: 14 additions & 5 deletions python/sandboxai/sandbox_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import os
import pytest
from sandboxai import Sandbox
from sandboxai.sandbox import DEFAULT_IMAGE

import logging

logging.basicConfig(level=logging.DEBUG)


@pytest.fixture
def box_image():
return os.environ.get("BOX_IMAGE", DEFAULT_IMAGE)
return os.environ.get("BOX_IMAGE")


@pytest.fixture
Expand Down Expand Up @@ -53,14 +56,20 @@ def test_sandbox_lazy_create(box_image):

def test_with_specified_name(box_image):
try:
sb = Sandbox(embedded=True, lazy_create=True, image=box_image, name="test-name")
assert sb.name == "test-name"
sb.create()
sb = Sandbox(embedded=True, image=box_image, name="test-name")
assert sb.name == "test-name"
finally:
sb.delete()


def test_non_embedded(base_url):
try:
sb = Sandbox(base_url=base_url)
assert sb.image
finally:
sb.delete()


# These tests pass locally but fail on github actions.
# def test_sandbox_embedded_server():
# with Sandbox(embedded=True) as sb:
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ go test -v .
cd $repo_root

cd $repo_root/python
uv run pytest
uv run pytest -o log_cli=true
cd $repo_root
Loading