feat(sandbox): add pending domains support for network sandbox

This commit is contained in:
yiling
2026-06-15 00:01:55 +08:00
parent 9c3b808809
commit 6a63e99044
14 changed files with 242 additions and 31 deletions
+42 -5
View File
@@ -97,7 +97,10 @@ If you need to create files in the local filesystem (for example, a temporary fi
systemPrompt += `\n\nYour current model supports the following input types: ${modelConfig.input.join(', ')}.`
}
let blockedHost = ''
const { session, harness } = await createAgentSession({
teamId: params.teamId,
agentId: params.agentId,
providerName,
modelId,
@@ -121,6 +124,9 @@ If you need to create files in the local filesystem (for example, a temporary fi
config: m.config,
})),
})),
onNetworkBlocked: (host) => {
blockedHost = host
},
})
const imagesToPass: ImageContent[] = []
@@ -142,6 +148,24 @@ If you need to create files in the local filesystem (for example, a temporary fi
try {
const assistantMessage = await harness.prompt(params.prompt, { images: imagesToPass })
const storage = session.getStorage()
let sessionId = ''
if (storage instanceof DatabaseSessionStorage) {
sessionId = storage.sessionId
}
if (blockedHost) {
return {
text: `Network request to ${blockedHost} is blocked, please ask admin to allow it in sandbox settings.`,
usage: {
model: modelId,
inputTokens: assistantMessage.usage?.input || 0,
outputTokens: assistantMessage.usage?.output || 0,
},
sessionId,
}
}
const sessionEntries = await session.getEntries()
sessionEntries.forEach((entry) => {
if (entry.type === 'message') {
@@ -178,12 +202,25 @@ If you need to create files in the local filesystem (for example, a temporary fi
outputTokens: assistantMessage.usage?.output || 0,
}
const storage = session.getStorage()
let sessionId = ''
if (storage instanceof DatabaseSessionStorage) {
sessionId = storage.sessionId
}
return { text, usage, sessionId }
} catch (err) {
if (blockedHost) {
const storage = session.getStorage()
let sessionId = ''
if (storage instanceof DatabaseSessionStorage) {
sessionId = storage.sessionId
}
return {
text: `Network request to ${blockedHost} is blocked, please ask admin to allow it in sandbox settings.`,
usage: {
model: modelId,
inputTokens: 0,
outputTokens: 0,
},
sessionId,
}
}
throw err
} finally {
// Cleanup handled by agent session if needed
}
@@ -316,6 +316,7 @@ describe('DatabaseSessionStorage', () => {
// 6. Resume the session via createAgentSession
await createAgentSession({
teamId: 't1',
agentId: agent.id,
providerName: 'test-provider',
modelId: 'test-model',
@@ -424,6 +425,7 @@ describe('DatabaseSessionStorage', () => {
// 3. Resume the session via createAgentSession with a NEW comment ID
await createAgentSession({
teamId: 't1',
agentId: agent.id,
providerName: 'test-provider',
modelId: 'test-model',
+50 -10
View File
@@ -5,6 +5,7 @@ import { getModel } from '@earendil-works/pi-ai'
import { Type, type TSchema } from '@sinclair/typebox'
import * as fs from 'fs'
import * as path from 'path'
import { prisma } from '@shumai/db'
import { agentService } from '@shumai/core/src/agent/agent'
import { DatabaseSessionStorage } from './database-session-storage'
import { createAnalyzeImageTool } from './tools/analyze-image'
@@ -17,6 +18,7 @@ import { createReadSkillTool } from './tools/read-skill'
import { createSandboxedBashTool } from './tools/sandboxed-bash'
export interface CreateAgentSessionParams {
teamId: string
agentId: string
providerName: string
modelId: string
@@ -36,10 +38,12 @@ export interface CreateAgentSessionParams {
config: PrismaJson.ModelConfig
}>
}>
onNetworkBlocked?: (host: string) => void
}
export async function createAgentSession(params: CreateAgentSessionParams) {
const {
teamId,
agentId,
providerName,
modelId,
@@ -115,18 +119,54 @@ export async function createAgentSession(params: CreateAgentSessionParams) {
const allowWrite = [piDir]
const sandboxAskCallback = async ({ host, port }: { host: string; port?: number }) => {
const hostPort = port ? `${host}:${port}` : host
try {
const sandbox = await prisma.sandbox.findUnique({
where: { teamId },
})
const pendingDomains = sandbox?.pendingDomains || []
if (!pendingDomains.includes(hostPort)) {
await prisma.sandbox.upsert({
where: { teamId },
create: {
teamId,
pendingDomains: [hostPort],
},
update: {
pendingDomains: {
push: hostPort,
},
},
})
}
} catch (err) {
console.error('Failed to update sandbox pending domains:', err)
}
if (params.onNetworkBlocked) {
params.onNetworkBlocked(hostPort)
}
return false
}
// SandboxManager.initialize is a global operation that applies to the entire process.
await SandboxManager.initialize({
network: {
allowedDomains,
deniedDomains: [],
await SandboxManager.initialize(
{
network: {
allowedDomains,
deniedDomains: [],
},
filesystem: {
denyRead: ['.env', '.env.*', '*.pem', '*.key'],
allowWrite,
denyWrite: ['.env', '.env.*', '*.pem', '*.key'],
},
},
filesystem: {
denyRead: ['.env', '.env.*', '*.pem', '*.key'],
allowWrite,
denyWrite: ['.env', '.env.*', '*.pem', '*.key'],
},
})
sandboxAskCallback,
)
const skillEnvs: Record<string, string> = {}
const onEnvsAdded = (envs: Record<string, string>) => {
+15 -4
View File
@@ -268,13 +268,17 @@ describe('team api', () => {
})
it('GET /teams/:teamId/sandbox returns sandbox settings', async () => {
mockGetSandboxSettings.mockResolvedValue({ allowedDomains: ['example.com'] })
mockGetSandboxSettings.mockResolvedValue({
allowedDomains: ['example.com'],
pendingDomains: ['pending.com'],
})
const res = await app.request('/teams/t1/sandbox')
expect(res.status).toBe(200)
const data = await res.json()
expect(data.allowedDomains).toEqual(['example.com'])
expect(data.pendingDomains).toEqual(['pending.com'])
expect(authzService.hasPermission).toHaveBeenCalledWith(
expect.objectContaining({
type: ResourceType.Team,
@@ -286,17 +290,21 @@ describe('team api', () => {
})
it('PUT /teams/:teamId/sandbox updates sandbox settings', async () => {
mockUpdateSandboxSettings.mockResolvedValue({ allowedDomains: ['new.com'] })
mockUpdateSandboxSettings.mockResolvedValue({
allowedDomains: ['new.com'],
pendingDomains: ['new-pending.com'],
})
const res = await app.request('/teams/t1/sandbox', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ allowedDomains: ['new.com'] }),
body: JSON.stringify({ allowedDomains: ['new.com'], pendingDomains: ['new-pending.com'] }),
})
expect(res.status).toBe(200)
const data = await res.json()
expect(data.allowedDomains).toEqual(['new.com'])
expect(data.pendingDomains).toEqual(['new-pending.com'])
expect(authzService.hasPermission).toHaveBeenCalledWith(
expect.objectContaining({
type: ResourceType.Team,
@@ -304,6 +312,9 @@ describe('team api', () => {
permission: Permission.Admin,
}),
)
expect(mockUpdateSandboxSettings).toHaveBeenCalledWith('t1', { allowedDomains: ['new.com'] })
expect(mockUpdateSandboxSettings).toHaveBeenCalledWith('t1', {
allowedDomains: ['new.com'],
pendingDomains: ['new-pending.com'],
})
})
})
+5
View File
@@ -290,16 +290,20 @@ describe('TeamService', () => {
// Should have default settings
const settings = await teamService.getSandboxSettings(team.id)
expect(settings.allowedDomains).toContain('github.com')
expect(settings.pendingDomains).toEqual([])
// Should update settings
const updated = await teamService.updateSandboxSettings(team.id, {
allowedDomains: ['example.com'],
pendingDomains: ['pending.com'],
})
expect(updated.allowedDomains).toEqual(['example.com'])
expect(updated.pendingDomains).toEqual(['pending.com'])
// Should persist to DB
const persisted = await teamService.getSandboxSettings(team.id)
expect(persisted.allowedDomains).toEqual(['example.com'])
expect(persisted.pendingDomains).toEqual(['pending.com'])
})
it('should return empty allowedDomains if sandbox is missing for old team', async () => {
@@ -309,5 +313,6 @@ describe('TeamService', () => {
const settings = await teamService.getSandboxSettings(team.id)
expect(settings.allowedDomains).toEqual([])
expect(settings.pendingDomains).toEqual([])
})
})
+4
View File
@@ -322,6 +322,7 @@ export class TeamService {
})
return {
allowedDomains: sandbox?.allowedDomains || [],
pendingDomains: sandbox?.pendingDomains || [],
}
}
@@ -331,13 +332,16 @@ export class TeamService {
create: {
teamId,
allowedDomains: settings.allowedDomains,
pendingDomains: settings.pendingDomains,
},
update: {
allowedDomains: settings.allowedDomains,
pendingDomains: settings.pendingDomains,
},
})
return {
allowedDomains: sandbox.allowedDomains,
pendingDomains: sandbox.pendingDomains,
}
}
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "sandboxes" ADD COLUMN "pending_domains" TEXT[] DEFAULT ARRAY[]::TEXT[];
+1
View File
@@ -236,6 +236,7 @@ model Team {
model Sandbox {
id String @id @default(ulid())
allowedDomains String[] @default(["npmjs.org", "*.npmjs.org", "registry.npmjs.org", "registry.yarnpkg.com", "pypi.org", "*.pypi.org", "github.com", "*.github.com", "api.github.com", "raw.githubusercontent.com"])
pendingDomains String[] @default([]) @map("pending_domains")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
File diff suppressed because one or more lines are too long
@@ -2970,6 +2970,7 @@ export type TeamScalarFieldEnum = (typeof TeamScalarFieldEnum)[keyof typeof Team
export const SandboxScalarFieldEnum = {
id: 'id',
allowedDomains: 'allowedDomains',
pendingDomains: 'pendingDomains',
createdAt: 'createdAt',
updatedAt: 'updatedAt',
teamId: 'teamId',
@@ -185,6 +185,7 @@ export type TeamScalarFieldEnum = (typeof TeamScalarFieldEnum)[keyof typeof Team
export const SandboxScalarFieldEnum = {
id: 'id',
allowedDomains: 'allowedDomains',
pendingDomains: 'pendingDomains',
createdAt: 'createdAt',
updatedAt: 'updatedAt',
teamId: 'teamId',
@@ -42,6 +42,7 @@ export type SandboxMaxAggregateOutputType = {
export type SandboxCountAggregateOutputType = {
id: number
allowedDomains: number
pendingDomains: number
createdAt: number
updatedAt: number
teamId: number
@@ -65,6 +66,7 @@ export type SandboxMaxAggregateInputType = {
export type SandboxCountAggregateInputType = {
id?: true
allowedDomains?: true
pendingDomains?: true
createdAt?: true
updatedAt?: true
teamId?: true
@@ -147,6 +149,7 @@ export type SandboxGroupByArgs<
export type SandboxGroupByOutputType = {
id: string
allowedDomains: string[]
pendingDomains: string[]
createdAt: Date
updatedAt: Date
teamId: string
@@ -173,6 +176,7 @@ export type SandboxWhereInput = {
NOT?: Prisma.SandboxWhereInput | Prisma.SandboxWhereInput[]
id?: Prisma.StringFilter<'Sandbox'> | string
allowedDomains?: Prisma.StringNullableListFilter<'Sandbox'>
pendingDomains?: Prisma.StringNullableListFilter<'Sandbox'>
createdAt?: Prisma.DateTimeFilter<'Sandbox'> | Date | string
updatedAt?: Prisma.DateTimeFilter<'Sandbox'> | Date | string
teamId?: Prisma.StringFilter<'Sandbox'> | string
@@ -182,6 +186,7 @@ export type SandboxWhereInput = {
export type SandboxOrderByWithRelationInput = {
id?: Prisma.SortOrder
allowedDomains?: Prisma.SortOrder
pendingDomains?: Prisma.SortOrder
createdAt?: Prisma.SortOrder
updatedAt?: Prisma.SortOrder
teamId?: Prisma.SortOrder
@@ -196,6 +201,7 @@ export type SandboxWhereUniqueInput = Prisma.AtLeast<
OR?: Prisma.SandboxWhereInput[]
NOT?: Prisma.SandboxWhereInput | Prisma.SandboxWhereInput[]
allowedDomains?: Prisma.StringNullableListFilter<'Sandbox'>
pendingDomains?: Prisma.StringNullableListFilter<'Sandbox'>
createdAt?: Prisma.DateTimeFilter<'Sandbox'> | Date | string
updatedAt?: Prisma.DateTimeFilter<'Sandbox'> | Date | string
team?: Prisma.XOR<Prisma.TeamScalarRelationFilter, Prisma.TeamWhereInput>
@@ -206,6 +212,7 @@ export type SandboxWhereUniqueInput = Prisma.AtLeast<
export type SandboxOrderByWithAggregationInput = {
id?: Prisma.SortOrder
allowedDomains?: Prisma.SortOrder
pendingDomains?: Prisma.SortOrder
createdAt?: Prisma.SortOrder
updatedAt?: Prisma.SortOrder
teamId?: Prisma.SortOrder
@@ -224,6 +231,7 @@ export type SandboxScalarWhereWithAggregatesInput = {
| Prisma.SandboxScalarWhereWithAggregatesInput[]
id?: Prisma.StringWithAggregatesFilter<'Sandbox'> | string
allowedDomains?: Prisma.StringNullableListFilter<'Sandbox'>
pendingDomains?: Prisma.StringNullableListFilter<'Sandbox'>
createdAt?: Prisma.DateTimeWithAggregatesFilter<'Sandbox'> | Date | string
updatedAt?: Prisma.DateTimeWithAggregatesFilter<'Sandbox'> | Date | string
teamId?: Prisma.StringWithAggregatesFilter<'Sandbox'> | string
@@ -232,6 +240,7 @@ export type SandboxScalarWhereWithAggregatesInput = {
export type SandboxCreateInput = {
id?: string
allowedDomains?: Prisma.SandboxCreateallowedDomainsInput | string[]
pendingDomains?: Prisma.SandboxCreatependingDomainsInput | string[]
createdAt?: Date | string
updatedAt?: Date | string
team: Prisma.TeamCreateNestedOneWithoutSandboxInput
@@ -240,6 +249,7 @@ export type SandboxCreateInput = {
export type SandboxUncheckedCreateInput = {
id?: string
allowedDomains?: Prisma.SandboxCreateallowedDomainsInput | string[]
pendingDomains?: Prisma.SandboxCreatependingDomainsInput | string[]
createdAt?: Date | string
updatedAt?: Date | string
teamId: string
@@ -248,6 +258,7 @@ export type SandboxUncheckedCreateInput = {
export type SandboxUpdateInput = {
id?: Prisma.StringFieldUpdateOperationsInput | string
allowedDomains?: Prisma.SandboxUpdateallowedDomainsInput | string[]
pendingDomains?: Prisma.SandboxUpdatependingDomainsInput | string[]
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
team?: Prisma.TeamUpdateOneRequiredWithoutSandboxNestedInput
@@ -256,6 +267,7 @@ export type SandboxUpdateInput = {
export type SandboxUncheckedUpdateInput = {
id?: Prisma.StringFieldUpdateOperationsInput | string
allowedDomains?: Prisma.SandboxUpdateallowedDomainsInput | string[]
pendingDomains?: Prisma.SandboxUpdatependingDomainsInput | string[]
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
teamId?: Prisma.StringFieldUpdateOperationsInput | string
@@ -264,6 +276,7 @@ export type SandboxUncheckedUpdateInput = {
export type SandboxCreateManyInput = {
id?: string
allowedDomains?: Prisma.SandboxCreateallowedDomainsInput | string[]
pendingDomains?: Prisma.SandboxCreatependingDomainsInput | string[]
createdAt?: Date | string
updatedAt?: Date | string
teamId: string
@@ -272,6 +285,7 @@ export type SandboxCreateManyInput = {
export type SandboxUpdateManyMutationInput = {
id?: Prisma.StringFieldUpdateOperationsInput | string
allowedDomains?: Prisma.SandboxUpdateallowedDomainsInput | string[]
pendingDomains?: Prisma.SandboxUpdatependingDomainsInput | string[]
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
}
@@ -279,6 +293,7 @@ export type SandboxUpdateManyMutationInput = {
export type SandboxUncheckedUpdateManyInput = {
id?: Prisma.StringFieldUpdateOperationsInput | string
allowedDomains?: Prisma.SandboxUpdateallowedDomainsInput | string[]
pendingDomains?: Prisma.SandboxUpdatependingDomainsInput | string[]
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
teamId?: Prisma.StringFieldUpdateOperationsInput | string
@@ -300,6 +315,7 @@ export type StringNullableListFilter<$PrismaModel = never> = {
export type SandboxCountOrderByAggregateInput = {
id?: Prisma.SortOrder
allowedDomains?: Prisma.SortOrder
pendingDomains?: Prisma.SortOrder
createdAt?: Prisma.SortOrder
updatedAt?: Prisma.SortOrder
teamId?: Prisma.SortOrder
@@ -379,14 +395,24 @@ export type SandboxCreateallowedDomainsInput = {
set: string[]
}
export type SandboxCreatependingDomainsInput = {
set: string[]
}
export type SandboxUpdateallowedDomainsInput = {
set?: string[]
push?: string | string[]
}
export type SandboxUpdatependingDomainsInput = {
set?: string[]
push?: string | string[]
}
export type SandboxCreateWithoutTeamInput = {
id?: string
allowedDomains?: Prisma.SandboxCreateallowedDomainsInput | string[]
pendingDomains?: Prisma.SandboxCreatependingDomainsInput | string[]
createdAt?: Date | string
updatedAt?: Date | string
}
@@ -394,6 +420,7 @@ export type SandboxCreateWithoutTeamInput = {
export type SandboxUncheckedCreateWithoutTeamInput = {
id?: string
allowedDomains?: Prisma.SandboxCreateallowedDomainsInput | string[]
pendingDomains?: Prisma.SandboxCreatependingDomainsInput | string[]
createdAt?: Date | string
updatedAt?: Date | string
}
@@ -429,6 +456,7 @@ export type SandboxUpdateToOneWithWhereWithoutTeamInput = {
export type SandboxUpdateWithoutTeamInput = {
id?: Prisma.StringFieldUpdateOperationsInput | string
allowedDomains?: Prisma.SandboxUpdateallowedDomainsInput | string[]
pendingDomains?: Prisma.SandboxUpdatependingDomainsInput | string[]
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
}
@@ -436,6 +464,7 @@ export type SandboxUpdateWithoutTeamInput = {
export type SandboxUncheckedUpdateWithoutTeamInput = {
id?: Prisma.StringFieldUpdateOperationsInput | string
allowedDomains?: Prisma.SandboxUpdateallowedDomainsInput | string[]
pendingDomains?: Prisma.SandboxUpdatependingDomainsInput | string[]
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
}
@@ -446,6 +475,7 @@ export type SandboxSelect<
{
id?: boolean
allowedDomains?: boolean
pendingDomains?: boolean
createdAt?: boolean
updatedAt?: boolean
teamId?: boolean
@@ -460,6 +490,7 @@ export type SandboxSelectCreateManyAndReturn<
{
id?: boolean
allowedDomains?: boolean
pendingDomains?: boolean
createdAt?: boolean
updatedAt?: boolean
teamId?: boolean
@@ -474,6 +505,7 @@ export type SandboxSelectUpdateManyAndReturn<
{
id?: boolean
allowedDomains?: boolean
pendingDomains?: boolean
createdAt?: boolean
updatedAt?: boolean
teamId?: boolean
@@ -485,6 +517,7 @@ export type SandboxSelectUpdateManyAndReturn<
export type SandboxSelectScalar = {
id?: boolean
allowedDomains?: boolean
pendingDomains?: boolean
createdAt?: boolean
updatedAt?: boolean
teamId?: boolean
@@ -493,7 +526,7 @@ export type SandboxSelectScalar = {
export type SandboxOmit<
ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs,
> = runtime.Types.Extensions.GetOmit<
'id' | 'allowedDomains' | 'createdAt' | 'updatedAt' | 'teamId',
'id' | 'allowedDomains' | 'pendingDomains' | 'createdAt' | 'updatedAt' | 'teamId',
ExtArgs['result']['sandbox']
>
export type SandboxInclude<
@@ -523,6 +556,7 @@ export type $SandboxPayload<
{
id: string
allowedDomains: string[]
pendingDomains: string[]
createdAt: Date
updatedAt: Date
teamId: string
@@ -1088,6 +1122,7 @@ export interface Prisma__SandboxClient<
export interface SandboxFieldRefs {
readonly id: Prisma.FieldRef<'Sandbox', 'String'>
readonly allowedDomains: Prisma.FieldRef<'Sandbox', 'String[]'>
readonly pendingDomains: Prisma.FieldRef<'Sandbox', 'String[]'>
readonly createdAt: Prisma.FieldRef<'Sandbox', 'DateTime'>
readonly updatedAt: Prisma.FieldRef<'Sandbox', 'DateTime'>
readonly teamId: Prisma.FieldRef<'Sandbox', 'String'>
+1
View File
@@ -79,6 +79,7 @@ export type VideoTranscodeStrategy =
export const sandboxSettingsSchema = z.object({
allowedDomains: z.array(z.string()),
pendingDomains: z.array(z.string()).default([]),
})
export type SandboxSettings = z.infer<typeof sandboxSettingsSchema>
@@ -4,7 +4,7 @@ import { client } from '@/ui/api/client'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card'
import { Input } from '@/ui/components/ui/input'
import { Button } from '@/ui/components/ui/button'
import { Loader2, Plus, X, Globe } from 'lucide-react'
import { Loader2, Plus, X, Globe, Check, Trash2, ShieldAlert } from 'lucide-react'
import { toast } from 'sonner'
export function SandboxSettings({ teamId }: { teamId: string }) {
@@ -23,10 +23,10 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
})
const { mutate: updateSandbox, isPending: isUpdating } = useMutation({
mutationFn: async (allowedDomains: string[]) => {
mutationFn: async (params: { allowedDomains: string[]; pendingDomains: string[] }) => {
const res = await client.api.teams[':teamId'].sandbox.$put({
param: { teamId },
json: { allowedDomains },
json: params,
})
if (!res.ok) throw new Error('Failed to update sandbox settings')
return await res.json()
@@ -47,14 +47,27 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
toast.error('Domain already exists')
return
}
const updated = [...(sandbox?.allowedDomains || []), newDomain.trim()]
updateSandbox(updated)
const updatedAllowed = [...(sandbox?.allowedDomains || []), newDomain.trim()]
const updatedPending = sandbox?.pendingDomains || []
updateSandbox({ allowedDomains: updatedAllowed, pendingDomains: updatedPending })
setNewDomain('')
}
const handleRemoveDomain = (domain: string) => {
const updated = (sandbox?.allowedDomains || []).filter((d) => d !== domain)
updateSandbox(updated)
const updatedAllowed = (sandbox?.allowedDomains || []).filter((d) => d !== domain)
const updatedPending = sandbox?.pendingDomains || []
updateSandbox({ allowedDomains: updatedAllowed, pendingDomains: updatedPending })
}
const handleApproveDomain = (domain: string) => {
const updatedAllowed = [...(sandbox?.allowedDomains || []), domain]
const updatedPending = (sandbox?.pendingDomains || []).filter((d) => d !== domain)
updateSandbox({ allowedDomains: updatedAllowed, pendingDomains: updatedPending })
}
const handleDeletePendingDomain = (domain: string) => {
const updatedPending = (sandbox?.pendingDomains || []).filter((d) => d !== domain)
updateSandbox({ allowedDomains: sandbox?.allowedDomains || [], pendingDomains: updatedPending })
}
if (isLoading) {
@@ -122,6 +135,64 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
</CardContent>
</Card>
{/* Pending Domains Section */}
<Card className="border-amber-200 dark:border-amber-900 bg-amber-50/10 dark:bg-amber-950/5">
<CardHeader>
<div className="flex items-center gap-2">
<ShieldAlert className="w-5 h-5 text-amber-500" />
<CardTitle>Pending Domain Approvals</CardTitle>
</div>
<CardDescription>
These domains were blocked during agent execution. You can approve them to allow future
network requests, or delete them from this list.
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-3">
{sandbox?.pendingDomains && sandbox.pendingDomains.length > 0 ? (
<div className="divide-y divide-slate-100 dark:divide-slate-800">
{sandbox.pendingDomains.map((domain) => (
<div
key={domain}
className="flex items-center justify-between py-2.5 first:pt-0 last:pb-0"
>
<span className="font-mono text-sm text-slate-700 dark:text-slate-300 bg-slate-100 dark:bg-slate-800 px-2 py-1 rounded">
{domain}
</span>
<div className="flex items-center gap-2">
<Button
size="sm"
variant="outline"
className="h-8 border-emerald-200 text-emerald-600 hover:bg-emerald-50 hover:text-emerald-700 dark:border-emerald-900 dark:text-emerald-400 dark:hover:bg-emerald-950/20"
onClick={() => handleApproveDomain(domain)}
disabled={isUpdating}
>
<Check className="w-4 h-4 mr-1.5" />
Approve
</Button>
<Button
size="sm"
variant="outline"
className="h-8 border-red-200 text-red-600 hover:bg-red-50 hover:text-red-700 dark:border-red-900 dark:text-red-400 dark:hover:bg-red-950/20"
onClick={() => handleDeletePendingDomain(domain)}
disabled={isUpdating}
>
<Trash2 className="w-4 h-4 mr-1.5" />
Delete
</Button>
</div>
</div>
))}
</div>
) : (
<div className="text-sm text-slate-400 italic py-2">
No pending domains requiring approval
</div>
)}
</div>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle>Filesystem Restriction</CardTitle>