1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum SandboxError {
8 #[error("code validation failed: {reason}")]
10 ValidationFailed {
11 reason: String,
13 },
14
15 #[error("code exceeds maximum size of {max} bytes (got {actual})")]
17 CodeTooLarge {
18 max: usize,
20 actual: usize,
22 },
23
24 #[error("output exceeds maximum size of {max} bytes")]
26 OutputTooLarge {
27 max: usize,
29 },
30
31 #[error("execution timed out after {timeout_ms}ms")]
33 Timeout {
34 timeout_ms: u64,
36 },
37
38 #[error("banned pattern detected: `{pattern}` — the sandbox has no filesystem, network, or module access. Use forge.callTool() or forge.server() to interact with external services.")]
40 BannedPattern {
41 pattern: String,
43 },
44
45 #[error("sandbox execution failed: {0}")]
47 Execution(#[from] anyhow::Error),
48
49 #[error("javascript error: {message}")]
51 JsError {
52 message: String,
54 },
55
56 #[error("result serialization failed: {0}")]
58 Serialization(#[from] serde_json::Error),
59
60 #[error("concurrency limit reached (max {max} concurrent executions)")]
62 ConcurrencyLimit {
63 max: usize,
65 },
66
67 #[error("tool call limit exceeded (max {max} calls per execution)")]
69 ToolCallLimit {
70 max: usize,
72 },
73
74 #[error("tool call arguments too large (max {max} bytes, got {actual})")]
76 ToolCallArgsTooLarge {
77 max: usize,
79 actual: usize,
81 },
82
83 #[error("V8 heap limit exceeded")]
85 HeapLimitExceeded,
86}