feat(sandbox): reject blocked request on bash tool result

This commit is contained in:
yiling
2026-06-15 09:28:11 +08:00
parent 6a63e99044
commit e9e096ac9e
5 changed files with 161 additions and 48 deletions
+5 -41
View File
@@ -97,8 +97,6 @@ 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,
@@ -124,9 +122,6 @@ 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[] = []
@@ -148,24 +143,6 @@ 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') {
@@ -202,25 +179,12 @@ If you need to create files in the local filesystem (for example, a temporary fi
outputTokens: assistantMessage.usage?.output || 0,
}
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,
}
const storage = session.getStorage()
let sessionId = ''
if (storage instanceof DatabaseSessionStorage) {
sessionId = storage.sessionId
}
throw err
return { text, usage, sessionId }
} finally {
// Cleanup handled by agent session if needed
}