Skip to content

An open-source, faster Devin alternative

TypeScript

adjustments

Brian Reardon9e88078549de
diff --git a/cmd/server/main.go b/cmd/server/main.go
index b9fbe6f7..3f4f5490 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -33,39 +33,33 @@ func main() {
ctx := context.Background()
- // Initialize Podman (optional in server mode — no container runtime needed)
+ // Initialize Podman (skipped in server mode — server delegates to workers via gRPC)
var mgr sandbox.Manager
var ptyMgr *sandbox.PTYManager
- podmanClient, err := podman.NewClient()
- if err != nil {
- if cfg.Mode == "server" {
- log.Printf("opensandbox: podman not available (server-only mode, sandbox execution disabled): %v", err)
- } else {
+ if cfg.Mode == "server" {
+ log.Printf("opensandbox: server mode — skipping local podman/sandbox manager (delegating to workers)")
+ } else {
+ podmanClient, err := podman.NewClient()
+ if err != nil {
log.Fatalf("failed to initialize podman: %v", err)
}
- } else {
version, err := podmanClient.Version(ctx)
if err != nil {
- if cfg.Mode == "server" {
- log.Printf("opensandbox: podman not responding (server-only mode, sandbox execution disabled): %v", err)
- } else {
- log.Fatalf("failed to get podman version: %v", err)
- }
- } else {
- log.Printf("opensandbox: using podman %s", version)
+ log.Fatalf("failed to get podman version: %v", err)
+ }
+ log.Printf("opensandbox: using podman %s", version)
- mgr = sandbox.NewManager(podmanClient,
- sandbox.WithDataDir(cfg.DataDir),
- sandbox.WithDefaultMemoryMB(cfg.DefaultSandboxMemoryMB),
- sandbox.WithDefaultCPUs(cfg.DefaultSandboxCPUs),
- sandbox.WithDefaultDiskMB(cfg.DefaultSandboxDiskMB),
- )
- defer mgr.Close()
+ mgr = sandbox.NewManager(podmanClient,
+ sandbox.WithDataDir(cfg.DataDir),
+ sandbox.WithDefaultMemoryMB(cfg.DefaultSandboxMemoryMB),
+ sandbox.WithDefaultCPUs(cfg.DefaultSandboxCPUs),
+ sandbox.WithDefaultDiskMB(cfg.DefaultSandboxDiskMB),
+ )
+ defer mgr.Close()
- podmanPath, _ := exec.LookPath("podman")
- ptyMgr = sandbox.NewPTYManager(podmanPath, podmanClient.AuthFile())
- defer ptyMgr.CloseAll()
- }
+ podmanPath, _ := exec.LookPath("podman")
+ ptyMgr = sandbox.NewPTYManager(podmanPath, podmanClient.AuthFile())
+ defer ptyMgr.CloseAll()
}
// Build server options
diff --git a/internal/api/dashboard.go b/internal/api/dashboard.go
index c43899cf..343a9078 100644
--- a/internal/api/dashboard.go
+++ b/internal/api/dashboard.go
@@ -456,7 +456,7 @@ func (s *Server) dashboardListTemplates(c echo.Context) error {
})
}
- // Strip internal fields from dashboard response
+ // Strip internal fields and filter: only show "default" as built-in template.
type safeTemplate struct {
ID uuid.UUID `json:"id"`
OrgID *uuid.UUID `json:"orgId,omitempty"`
@@ -468,14 +468,18 @@ func (s *Server) dashboardListTemplates(c echo.Context) error {
Status string `json:"status"`
CreatedAt time.Time `json:"createdAt"`
}
- safe := make([]safeTemplate, len(templates))
- for i, t := range templates {
- safe[i] = safeTemplate{
+ safe := make([]safeTemplate, 0, len(templates))
+ for _, t := range templates {
+ // Only show "default" as the built-in template; hide base, node, python, etc.
+ if t.IsPublic && t.Name != "default" {
+ continue
+ }
+ safe = append(safe, safeTemplate{
ID: t.ID, OrgID: t.OrgID, Name: t.Name,
Tag: t.Tag, IsPublic: t.IsPublic,
TemplateType: t.TemplateType, CreatedBySandboxID: t.CreatedBySandboxID,
Status: t.Status, CreatedAt: t.CreatedAt,
- }
+ })
}
return c.JSON(http.StatusOK, safe)
diff --git a/internal/api/router.go b/internal/api/router.go
index 578ace77..6aa2e8b5 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -188,7 +188,6 @@ func NewServer(mgr sandbox.Manager, ptyMgr *sandbox.PTYManager, apiKey string, o
dash.DELETE("/org/custom-domain", s.dashboardDeleteCustomDomain)
dash.POST("/org/custom-domain/refresh", s.dashboardRefreshCustomDomain)
dash.GET("/templates", s.dashboardListTemplates)
- dash.POST("/templates", s.dashboardBuildTemplate)
dash.DELETE("/templates/:id", s.dashboardDeleteTemplate)
// Session detail + stats
diff --git a/internal/api/sandbox.go b/internal/api/sandbox.go
index e217261c..8f98203e 100644
--- a/internal/api/sandbox.go
+++ b/internal/api/sandbox.go
@@ -119,7 +119,7 @@ func (s *Server) createSandbox(c echo.Context) error {
}
template := cfg.Template
if template == "" {
- template = "base"
+ template = "default"
}
_, _ = s.store.CreateSandboxSession(ctx, sb.ID, orgID, nil, template, region, workerID, cfgJSON, metadataJSON)
}
@@ -208,7 +208,7 @@ func (s *Server) createSandboxRemote(c echo.Context, ctx context.Context, cfg ty
if s.store != nil && hasOrg {
template := cfg.Template
if template == "" {
- template = "base"
+ template = "default"
}
cfgJSON, _ := json.Marshal(cfg)
metadataJSON, _ := json.Marshal(cfg.Metadata)
diff --git a/internal/firecracker/manager.go b/internal/firecracker/manager.go
index 7108fd63..fe1aa7c2 100644
--- a/internal/firecracker/manager.go
+++ b/internal/firecracker/manager.go
@@ -789,12 +789,27 @@ func (m *Manager) ContainerName(id string) string {
}
// Hibernate snapshots a VM and uploads to S3.
+// On success the Firecracker process is killed, network is torn down, and the
+// VM is removed from the in-memory tracking map so it no longer counts toward
+// worker capacity. The sandbox can later be restored via Wake().
func (m *Manager) Hibernate(ctx context.Context, sandboxID string, checkpointStore *storage.CheckpointStore) (*sandbox.HibernateResult, error) {
vm, err := m.getVM(sandboxID)
if err != nil {
return nil, err
}
- return m.doHibernate(ctx, vm, checkpointStore)
+ result, err := m.doHibernate(ctx, vm, checkpointStore)
+ if err != nil {
+ return nil, err
+ }
+
+ // Remove the VM from tracking — the Firecracker process is dead and
+ // resources (TAP, memory, CPU) are released. This frees the capacity
+ // slot so the worker can accept new sandboxes.
+ m.mu.Lock()
+ delete(m.vms, sandboxID)
+ m.mu.Unlock()
+
+ return result, nil
}
// Wake restores a VM from a snapshot.
diff --git a/web/src/api/client.ts b/web/src/api/client.ts
index 6c88d5c2..9feea4af 100644
--- a/web/src/api/client.ts
+++ b/web/src/api/client.ts
@@ -54,18 +54,18 @@ export const deleteAPIKey = (keyId: string) =>
export const getTemplates = () => apiFetch<Template[]>('/templates')
-export const buildTemplate = (name: string, dockerfile: string) =>
- apiFetch<Template>('/templates', {
- method: 'POST',
- body: JSON.stringify({ name, dockerfile }),
- })
-
export const deleteTemplate = (id: string) =>
apiFetch<void>(`/templates/${id}`, { method: 'DELETE' })
export const getSessionDetail = (sandboxId: string) =>
apiFetch<SessionDetail>(`/sessions/${sandboxId}`)
+export const saveAsTemplate = (sandboxId: string, name: string, tag?: string) =>
+ apiFetch<Template>(`/sessions/${sandboxId}/save-as-template`, {
+ method: 'POST',
+ body: JSON.stringify({ name, tag: tag || 'latest' }),
+ })
+
export const getSessionStats = (sandboxId: string) =>
apiFetch<SandboxStats>(`/sessions/${sandboxId}/stats`)
diff --git a/web/src/pages/SessionDetail.tsx b/web/src/pages/SessionDetail.tsx
index c1fd5606..a3b2ac39 100644
--- a/web/src/pages/SessionDetail.tsx
+++ b/web/src/pages/SessionDetail.tsx
@@ -1,7 +1,7 @@
import { useState } from 'react'
import { useParams, useNavigate } from 'react-router-dom'
-import { useQuery } from '@tanstack/react-query'
-import { getSessionDetail, getSessionStats } from '../api/client'
+import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
+import { getSessionDetail, getSessionStats, saveAsTemplate } from '../api/client'
import Terminal from '../components/Terminal'
function StatusBadge({ status }: { status: string }) {
@@ -63,12 +63,25 @@ export default function SessionDetail() {
const [showTerminal, setShowTerminal] = useState(false)
const [showInternal, setShowInternal] = useState(false)
+ const queryClient = useQueryClient()
+ const [showSaveTemplate, setShowSaveTemplate] = useState(false)
+ const [templateName, setTemplateName] = useState('')
+
const { data: session, isLoading } = useQuery({
queryKey: ['session-detail', sandboxId],
queryFn: () => getSessionDetail(sandboxId!),
enabled: !!sandboxId,
})
+ const saveTemplateMutation = useMutation({
+ mutationFn: () => saveAsTemplate(sandboxId!, templateName),
+ onSuccess: () => {
+ setShowSaveTemplate(false)
+ setTemplateName('')
+ queryClient.invalidateQueries({ queryKey: ['templates'] })
+ },
+ })
+
const { data: stats } = useQuery({
queryKey: ['session-stats', sandboxId],
queryFn: () => getSessionStats(sandboxId!),
@@ -134,16 +147,29 @@ export default function SessionDetail() {
{/* Actions */}
<div style={{ display: 'flex', gap: 8 }}>
{session.status === 'running' && (
- <button
- className={showTerminal ? 'btn-primary' : 'btn-ghost'}
- onClick={() => setShowTerminal(!showTerminal)}
- >
- <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
- <polyline points="4 17 10 11 4 5" />
- <line x1="12" y1="19" x2="20" y2="19" />
- </svg>
- Terminal
- </button>
+ <>
+ <button
+ className={showTerminal ? 'btn-primary' : 'btn-ghost'}
+ onClick={() => setShowTerminal(!showTerminal)}
+ >
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
+ <polyline points="4 17 10 11 4 5" />
+ <line x1="12" y1="19" x2="20" y2="19" />
+ </svg>
+ Terminal
+ </button>
+ <button
+ className="btn-ghost"
+ onClick={() => setShowSaveTemplate(true)}
+ >
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
+ <path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z" />
+ <polyline points="17 21 17 13 7 13 7 21" />
+ <polyline points="7 3 7 8 15 8" />
+ </svg>
+ Save as Template
+ </button>
+ </>
)}
</div>
</div>
@@ -156,6 +182,58 @@ export default function SessionDetail() {
</div>
)}
+ {/* Save as Template modal */}
+ {showSaveTemplate && (
+ <div className="glass-card animate-in" style={{ padding: 22, marginBottom: 16 }}>
+ <div style={{ fontSize: 11, fontWeight: 600, color: 'var(--text-tertiary)', textTransform: 'uppercase', letterSpacing: '0.05em', marginBottom: 14 }}>
+ Save as Template
+ </div>
+ <div style={{ marginBottom: 14 }}>
+ <label style={{ display: 'block', fontSize: 12, fontWeight: 600, color: 'var(--text-secondary)', marginBottom: 6 }}>
+ Template Name
+ </label>
+ <input
+ type="text"
+ value={templateName}
+ onChange={e => setTemplateName(e.target.value)}
+ placeholder="e.g. my-dev-environment"
+ className="input"
+ autoFocus
+ />
+ </div>
+ {saveTemplateMutation.isError && (
+ <div style={{
+ color: 'var(--accent-rose)',
+ fontSize: 12,
+ marginBottom: 12,
+ padding: '8px 12px',
+ background: 'rgba(244, 63, 94, 0.06)',
+ borderRadius: 'var(--radius-sm)',
+ border: '1px solid rgba(244, 63, 94, 0.15)',
+ }}>
+ {saveTemplateMutation.error?.message || 'Failed to save template'}
+ </div>
+ )}
+ <div style={{ display: 'flex', gap: 8 }}>
+ <button
+ className="btn-primary"
+ onClick={() => saveTemplateMutation.mutate()}
+ disabled={saveTemplateMutation.isPending || !templateName.trim()}
+ >
+ {saveTemplateMutation.isPending ? 'Saving...' : 'Save Template'}
+ </button>
+ <button className="btn-ghost" onClick={() => { setShowSaveTemplate(false); setTemplateName('') }}>
+ Cancel
+ </button>
+ </div>
+ {saveTemplateMutation.isPending && (
+ <div style={{ marginTop: 12, fontSize: 12, color: 'var(--text-tertiary)' }}>
+ Snapshotting sandbox filesystem. This may take a moment...
+ </div>
+ )}
+ </div>
+ )}
+
{/* Stats cards — only for running sandboxes */}
{session.status === 'running' && (
<div className="glass-card animate-in stagger-1" style={{ padding: 20, marginBottom: 16 }}>
diff --git a/web/src/pages/Templates.tsx b/web/src/pages/Templates.tsx
index 0ec12d75..ec6803e0 100644
--- a/web/src/pages/Templates.tsx
+++ b/web/src/pages/Templates.tsx
@@ -1,6 +1,5 @@
-import { useState } from 'react'
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
-import { getTemplates, buildTemplate, deleteTemplate, type Template } from '../api/client'
+import { getTemplates, deleteTemplate, type Template } from '../api/client'
export default function Templates() {
const queryClient = useQueryClient()
@@ -9,21 +8,6 @@ export default function Templates() {
queryFn: getTemplates,
})
- const [showCreate, setShowCreate] = useState(false)
- const [newName, setNewName] = useState('')
- const [newDockerfile, setNewDockerfile] = useState('')
-
- const buildMutation = useMutation({
- mutationFn: ({ name, dockerfile }: { name: string; dockerfile: string }) =>
- buildTemplate(name, dockerfile),
- onSuccess: () => {
- setShowCreate(false)
- setNewName('')
- setNewDockerfile('')
- queryClient.invalidateQueries({ queryKey: ['templates'] })
- },
- })
-
const deleteMutation = useMutation({
mutationFn: (id: string) => deleteTemplate(id),
onSuccess: () => {
@@ -34,86 +18,11 @@ export default function Templates() {
return (
<div>
{/* Header */}
- <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 28 }}>
- <div>
- <h1 className="page-title">Templates</h1>
- <p className="page-subtitle">Manage sandbox base images for your organization</p>
- </div>
- <button className="btn-primary" onClick={() => setShowCreate(true)}>
- <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round">
- <line x1="12" y1="5" x2="12" y2="19" /><line x1="5" y1="12" x2="19" y2="12" />
- </svg>
- Create Template
- </button>
+ <div style={{ marginBottom: 28 }}>
+ <h1 className="page-title">Templates</h1>
+ <p className="page-subtitle">Manage sandbox templates for your organization</p>
</div>
- {/* Create Dialog */}
- {showCreate && (
- <div className="glass-card animate-in" style={{ padding: 22, marginBottom: 20 }}>
- <div style={{ marginBottom: 14 }}>
- <label style={{ display: 'block', fontSize: 12, fontWeight: 600, color: 'var(--text-secondary)', marginBottom: 6 }}>
- Template Name
- </label>
- <input
- type="text"
- value={newName}
- onChange={e => setNewName(e.target.value)}
- placeholder="e.g. my-app"
- className="input"
- autoFocus
- />
- </div>
- <div style={{ marginBottom: 14 }}>
- <label style={{ display: 'block', fontSize: 12, fontWeight: 600, color: 'var(--text-secondary)', marginBottom: 6 }}>
- Dockerfile
- </label>
- <textarea
- value={newDockerfile}
- onChange={e => setNewDockerfile(e.target.value)}
- placeholder={'FROM ubuntu:22.04\nRUN apt-get update && apt-get install -y curl'}
- className="input"
- rows={8}
- style={{
- fontFamily: 'var(--font-mono)',
- fontSize: 13,
- resize: 'vertical',
- minHeight: 120,
- }}
- />
- </div>
- {buildMutation.isError && (
- <div style={{
- color: 'var(--accent-rose)',
- fontSize: 12,
- marginBottom: 12,
- padding: '8px 12px',
- background: 'rgba(244, 63, 94, 0.06)',
- borderRadius: 'var(--radius-sm)',
- border: '1px solid rgba(244, 63, 94, 0.15)',
- }}>
- {buildMutation.error?.message || 'Build failed'}
- </div>
- )}
- <div style={{ display: 'flex', gap: 8 }}>
- <button
- className="btn-primary"
- onClick={() => buildMutation.mutate({ name: newName, dockerfile: newDockerfile })}
- disabled={buildMutation.isPending || !newName.trim() || !newDockerfile.trim()}
- >
- {buildMutation.isPending ? 'Building\u2026' : 'Build Template'}
- </button>
- <button className="btn-ghost" onClick={() => { setShowCreate(false); setNewName(''); setNewDockerfile('') }}>
- Cancel
- </button>
- </div>
- {buildMutation.isPending && (
- <div style={{ marginTop: 12, fontSize: 12, color: 'var(--text-tertiary)' }}>
- Building image and pushing to registry. This may take a few minutes...
- </div>
- )}
- </div>
- )}
-
{/* Table */}
{isLoading ? (
<div style={{ display: 'flex', justifyContent: 'center', padding: 48 }}>