mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 20:28:42 +00:00
Merge pull request #109 from shumaiOne/feat/sandbox-pending-domains
feat(sandbox): add pending domains support for network sandbox
This commit is contained in:
@@ -98,6 +98,7 @@ If you need to create files in the local filesystem (for example, a temporary fi
|
||||
}
|
||||
|
||||
const { session, harness } = await createAgentSession({
|
||||
teamId: params.teamId,
|
||||
agentId: params.agentId,
|
||||
providerName,
|
||||
modelId,
|
||||
|
||||
@@ -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',
|
||||
@@ -334,6 +335,7 @@ describe('DatabaseSessionStorage', () => {
|
||||
expect.objectContaining({
|
||||
MOCK_ENV_VAR: 'mocked-value',
|
||||
}),
|
||||
expect.any(Object),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -424,6 +426,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',
|
||||
|
||||
@@ -1,6 +1,27 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { formatSkillsForPrompt } from './index'
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { formatSkillsForPrompt, createAgentSession } from './index'
|
||||
import { createSandboxedBashTool } from './tools/sandboxed-bash'
|
||||
import { SandboxManager, type SandboxAskCallback } from '@anthropic-ai/sandbox-runtime'
|
||||
import { prisma } from '@shumai/db'
|
||||
import { setupTestDbHooks } from '@shumai/db/test'
|
||||
import * as path from 'path'
|
||||
import * as childProcess from 'node:child_process'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let mockSpawn: any = null
|
||||
|
||||
vi.mock('node:child_process', async () => {
|
||||
const actual = (await vi.importActual('node:child_process')) as typeof childProcess
|
||||
return {
|
||||
...actual,
|
||||
spawn: (...args: Parameters<typeof childProcess.spawn>) => {
|
||||
if (mockSpawn) {
|
||||
return mockSpawn(...args)
|
||||
}
|
||||
return actual.spawn(...args)
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
describe('formatSkillsForPrompt', () => {
|
||||
it('should return empty string if skills array is empty', () => {
|
||||
@@ -31,3 +52,207 @@ describe('formatSkillsForPrompt', () => {
|
||||
expect(result).toContain('</available_skills>')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Sandbox Network isolation integration', () => {
|
||||
setupTestDbHooks()
|
||||
|
||||
it('should register callback that pushes blocked hosts to database and propagates to bash tool', async () => {
|
||||
// 1. Create a team
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'Test Sandbox Team' },
|
||||
})
|
||||
|
||||
// Ensure agent user and agent exist in database to avoid foreign key violation
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
id: 'test-agent',
|
||||
name: 'Ai Agent',
|
||||
email: 'test-agent@shumai.ai',
|
||||
type: 'agent',
|
||||
},
|
||||
})
|
||||
await prisma.agent.create({
|
||||
data: {
|
||||
id: 'test-agent',
|
||||
teamId: team.id,
|
||||
type: 'chat',
|
||||
config: {
|
||||
provider: 'openai',
|
||||
model: 'gpt-4',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// 2. Mock / spy SandboxManager
|
||||
const initializeSpy = vi.spyOn(SandboxManager, 'initialize').mockResolvedValue()
|
||||
const wrapSpy = vi
|
||||
.spyOn(SandboxManager, 'wrapWithSandbox')
|
||||
.mockImplementation(async (cmd) => cmd)
|
||||
|
||||
// 3. Call createAgentSession
|
||||
await createAgentSession({
|
||||
teamId: team.id,
|
||||
agentId: 'test-agent',
|
||||
providerName: 'google',
|
||||
modelId: 'gemini',
|
||||
systemPrompt: 'prompt',
|
||||
teamSkills: [],
|
||||
allowedDomains: [],
|
||||
providers: [],
|
||||
})
|
||||
|
||||
// 4. Verify SandboxManager.initialize was called and extract the callback
|
||||
expect(initializeSpy).toHaveBeenCalled()
|
||||
const callback = initializeSpy.mock.calls[0][1]
|
||||
expect(callback).toBeDefined()
|
||||
|
||||
// 5. Trigger the callback with a blocked host
|
||||
const result = await callback!({ host: 'blocked-api.com', port: 443 })
|
||||
expect(result).toBe(false) // should always return false to block
|
||||
|
||||
// 6. Verify it was pushed to database
|
||||
const sandbox = await prisma.sandbox.findUnique({
|
||||
where: { teamId: team.id },
|
||||
})
|
||||
expect(sandbox?.pendingDomains).toContain('blocked-api.com')
|
||||
|
||||
// 7. Verify that if the bash tool is run while a domain is blocked, it rejects with correct error
|
||||
const sandboxState = { blockedHost: '' }
|
||||
const bashTool = createSandboxedBashTool(
|
||||
process.cwd(),
|
||||
{},
|
||||
{
|
||||
getBlockedHost: () => sandboxState.blockedHost,
|
||||
clearBlockedHost: () => {
|
||||
sandboxState.blockedHost = ''
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
// Mock spawn to simulate process exit and trigger network block
|
||||
mockSpawn = () => {
|
||||
sandboxState.blockedHost = 'blocked-api.com'
|
||||
const mockChild = {
|
||||
pid: 123,
|
||||
stdout: { on: vi.fn() },
|
||||
stderr: { on: vi.fn() },
|
||||
on: vi.fn((event: string, cb: (code: number) => void) => {
|
||||
if (event === 'close') {
|
||||
setTimeout(() => cb(1), 10)
|
||||
}
|
||||
}),
|
||||
} as unknown as childProcess.ChildProcess
|
||||
return mockChild
|
||||
}
|
||||
|
||||
const bashPromise = bashTool.execute('1', { command: 'curl blocked-api.com' })
|
||||
|
||||
try {
|
||||
await expect(bashPromise).rejects.toThrow(
|
||||
'Network request to blocked-api.com is blocked, please ask admin to allow it in sandbox settings.',
|
||||
)
|
||||
} finally {
|
||||
mockSpawn = null
|
||||
initializeSpy.mockRestore()
|
||||
wrapSpy.mockRestore()
|
||||
}
|
||||
})
|
||||
|
||||
it('should correctly route sandbox callback to the active session when multiple sessions are created sequentially', async () => {
|
||||
// 1. Create two teams
|
||||
const team1 = await prisma.team.create({
|
||||
data: { name: 'Team 1' },
|
||||
})
|
||||
const team2 = await prisma.team.create({
|
||||
data: { name: 'Team 2' },
|
||||
})
|
||||
|
||||
// Ensure agent user and agents exist in database
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
id: 'agent-1',
|
||||
name: 'Ai Agent 1',
|
||||
email: 'agent1@shumai.ai',
|
||||
type: 'agent',
|
||||
},
|
||||
})
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
id: 'agent-2',
|
||||
name: 'Ai Agent 2',
|
||||
email: 'agent2@shumai.ai',
|
||||
type: 'agent',
|
||||
},
|
||||
})
|
||||
await prisma.agent.create({
|
||||
data: {
|
||||
id: 'agent-1',
|
||||
teamId: team1.id,
|
||||
type: 'chat',
|
||||
config: { provider: 'openai', model: 'gpt-4' },
|
||||
},
|
||||
})
|
||||
await prisma.agent.create({
|
||||
data: {
|
||||
id: 'agent-2',
|
||||
teamId: team2.id,
|
||||
type: 'chat',
|
||||
config: { provider: 'openai', model: 'gpt-4' },
|
||||
},
|
||||
})
|
||||
|
||||
// Mock SandboxManager.initialize to behave like a process-global singleton
|
||||
let registeredCallback: SandboxAskCallback | null = null
|
||||
const initializeSpy = vi.spyOn(SandboxManager, 'initialize').mockImplementation(async (config, cb) => {
|
||||
if (!registeredCallback) {
|
||||
registeredCallback = cb || null
|
||||
}
|
||||
})
|
||||
const resetSpy = vi.spyOn(SandboxManager, 'reset').mockImplementation(async () => {
|
||||
// In the real SandboxManager, reset clears the global initialization promise and servers,
|
||||
// which allows subsequent initialize calls to register a new callback.
|
||||
registeredCallback = null
|
||||
})
|
||||
|
||||
try {
|
||||
// 2. Call createAgentSession for Session 1
|
||||
await createAgentSession({
|
||||
teamId: team1.id,
|
||||
agentId: 'agent-1',
|
||||
providerName: 'google',
|
||||
modelId: 'gemini',
|
||||
systemPrompt: 'prompt',
|
||||
teamSkills: [],
|
||||
allowedDomains: [],
|
||||
providers: [],
|
||||
})
|
||||
|
||||
// 3. Call createAgentSession for Session 2
|
||||
await createAgentSession({
|
||||
teamId: team2.id,
|
||||
agentId: 'agent-2',
|
||||
providerName: 'google',
|
||||
modelId: 'gemini',
|
||||
systemPrompt: 'prompt',
|
||||
teamSkills: [],
|
||||
allowedDomains: [],
|
||||
providers: [],
|
||||
})
|
||||
|
||||
expect(registeredCallback).toBeDefined()
|
||||
|
||||
// 4. Trigger the globally registered callback (which is from Session 1)
|
||||
const result = await registeredCallback!({ host: 'blocked-for-session-2.com', port: 443 })
|
||||
expect(result).toBe(false)
|
||||
|
||||
// 5. Verify that the pending domain was pushed to the DB record of Team 2
|
||||
const sandbox2 = await prisma.sandbox.findUnique({
|
||||
where: { teamId: team2.id },
|
||||
})
|
||||
expect(sandbox2?.pendingDomains).toContain('blocked-for-session-2.com')
|
||||
} finally {
|
||||
initializeSpy.mockRestore()
|
||||
resetSpy.mockRestore()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
+58
-11
@@ -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
|
||||
@@ -40,6 +42,7 @@ export interface CreateAgentSessionParams {
|
||||
|
||||
export async function createAgentSession(params: CreateAgentSessionParams) {
|
||||
const {
|
||||
teamId,
|
||||
agentId,
|
||||
providerName,
|
||||
modelId,
|
||||
@@ -115,18 +118,57 @@ export async function createAgentSession(params: CreateAgentSessionParams) {
|
||||
|
||||
const allowWrite = [piDir]
|
||||
|
||||
const sandboxState = {
|
||||
blockedHost: '',
|
||||
}
|
||||
|
||||
const sandboxAskCallback = async ({ host }: { host: string; port?: number }) => {
|
||||
try {
|
||||
const sandbox = await prisma.sandbox.findUnique({
|
||||
where: { teamId },
|
||||
})
|
||||
const pendingDomains = sandbox?.pendingDomains || []
|
||||
if (!pendingDomains.includes(host)) {
|
||||
await prisma.sandbox.upsert({
|
||||
where: { teamId },
|
||||
create: {
|
||||
teamId,
|
||||
pendingDomains: [host],
|
||||
},
|
||||
update: {
|
||||
pendingDomains: {
|
||||
push: host,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to update sandbox pending domains:', err)
|
||||
}
|
||||
|
||||
sandboxState.blockedHost = host
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// SandboxManager.initialize is a global operation that applies to the entire process.
|
||||
await SandboxManager.initialize({
|
||||
network: {
|
||||
allowedDomains,
|
||||
deniedDomains: [],
|
||||
// We reset it first to ensure any previous process-global SOCKS/HTTP proxy servers
|
||||
// and callbacks are cleaned up, allowing the new callback and allowedDomains to take effect.
|
||||
await SandboxManager.reset()
|
||||
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>) => {
|
||||
@@ -169,7 +211,12 @@ export async function createAgentSession(params: CreateAgentSessionParams) {
|
||||
)
|
||||
}
|
||||
|
||||
const sandboxedBash = createSandboxedBashTool(process.cwd(), skillEnvs)
|
||||
const sandboxedBash = createSandboxedBashTool(process.cwd(), skillEnvs, {
|
||||
getBlockedHost: () => sandboxState.blockedHost,
|
||||
clearBlockedHost: () => {
|
||||
sandboxState.blockedHost = ''
|
||||
},
|
||||
})
|
||||
const readSkill = createReadSkillTool(onEnvsAdded)
|
||||
|
||||
const systemTools: AgentTool[] = []
|
||||
|
||||
@@ -15,9 +15,15 @@ type BashDetails = {
|
||||
stderr: string
|
||||
}
|
||||
|
||||
export interface SandboxedBashOptions {
|
||||
getBlockedHost?: () => string
|
||||
clearBlockedHost?: () => void
|
||||
}
|
||||
|
||||
export const createSandboxedBashTool = (
|
||||
cwd: string,
|
||||
skillEnvs: Record<string, string> = {},
|
||||
options?: SandboxedBashOptions,
|
||||
): AgentTool<typeof BashParameters, BashDetails> => {
|
||||
return {
|
||||
name: 'bash',
|
||||
@@ -29,6 +35,7 @@ export const createSandboxedBashTool = (
|
||||
{ command, timeout },
|
||||
signal,
|
||||
): Promise<AgentToolResult<BashDetails>> => {
|
||||
options?.clearBlockedHost?.()
|
||||
const wrappedCommand = await SandboxManager.wrapWithSandbox(command)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -94,12 +101,20 @@ export const createSandboxedBashTool = (
|
||||
if (timeoutHandle) clearTimeout(timeoutHandle)
|
||||
signal?.removeEventListener('abort', onAbort)
|
||||
|
||||
const blocked = options?.getBlockedHost?.()
|
||||
|
||||
if (signal?.aborted) {
|
||||
logger.error({ command, stdout, stderr }, 'Sandboxed bash command aborted')
|
||||
reject(new Error('aborted'))
|
||||
} else if (timedOut) {
|
||||
logger.error({ timeout, command, stdout, stderr }, 'Sandboxed bash command timed out')
|
||||
reject(new Error(`bash command timed out after ${timeout} seconds`))
|
||||
} else if (blocked) {
|
||||
reject(
|
||||
new Error(
|
||||
`Network request to ${blocked} is blocked, please ask admin to allow it in sandbox settings.`,
|
||||
),
|
||||
)
|
||||
} else if (code !== 0 && code !== null) {
|
||||
logger.error(
|
||||
{ exitCode: code, command, stdout, stderr },
|
||||
|
||||
@@ -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'],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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([])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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[];
|
||||
@@ -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'>
|
||||
|
||||
@@ -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 break-all">
|
||||
{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>
|
||||
|
||||
Reference in New Issue
Block a user